Fix address violations when reading corrupt VMS records.
[deliverable/binutils-gdb.git] / bfd / ieee.c
1 /* BFD back-end for ieee-695 objects.
2 Copyright (C) 1990-2017 Free Software Foundation, Inc.
3
4 Written by Steve Chamberlain of 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 3 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
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
22
23
24 #define KEEPMINUSPCININST 0
25
26 /* IEEE 695 format is a stream of records, which we parse using a simple one-
27 token (which is one byte in this lexicon) lookahead recursive decent
28 parser. */
29
30 #include "sysdep.h"
31 #include "bfd.h"
32 #include "libbfd.h"
33 #include "ieee.h"
34 #include "libieee.h"
35 #include "safe-ctype.h"
36 #include "libiberty.h"
37
38 struct output_buffer_struct
39 {
40 unsigned char *ptrp;
41 int buffer;
42 };
43
44 static unsigned char *output_ptr_start;
45 static unsigned char *output_ptr;
46 static unsigned char *output_ptr_end;
47 static unsigned char *input_ptr_start;
48 static unsigned char *input_ptr;
49 static unsigned char *input_ptr_end;
50 static bfd *input_bfd;
51 static bfd *output_bfd;
52 static int output_buffer;
53
54
55 static void block (void);
56
57 /* Functions for writing to ieee files in the strange way that the
58 standard requires. */
59
60 static bfd_boolean
61 ieee_write_byte (bfd *abfd, int barg)
62 {
63 bfd_byte byte;
64
65 byte = barg;
66 if (bfd_bwrite ((void *) &byte, (bfd_size_type) 1, abfd) != 1)
67 return FALSE;
68 return TRUE;
69 }
70
71 static bfd_boolean
72 ieee_write_2bytes (bfd *abfd, int bytes)
73 {
74 bfd_byte buffer[2];
75
76 buffer[0] = bytes >> 8;
77 buffer[1] = bytes & 0xff;
78 if (bfd_bwrite ((void *) buffer, (bfd_size_type) 2, abfd) != 2)
79 return FALSE;
80 return TRUE;
81 }
82
83 static bfd_boolean
84 ieee_write_int (bfd *abfd, bfd_vma value)
85 {
86 if (value <= 127)
87 {
88 if (! ieee_write_byte (abfd, (bfd_byte) value))
89 return FALSE;
90 }
91 else
92 {
93 unsigned int length;
94
95 /* How many significant bytes ? */
96 /* FIXME FOR LONGER INTS. */
97 if (value & 0xff000000)
98 length = 4;
99 else if (value & 0x00ff0000)
100 length = 3;
101 else if (value & 0x0000ff00)
102 length = 2;
103 else
104 length = 1;
105
106 if (! ieee_write_byte (abfd,
107 (bfd_byte) ((int) ieee_number_repeat_start_enum
108 + length)))
109 return FALSE;
110 switch (length)
111 {
112 case 4:
113 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))
114 return FALSE;
115 /* Fall through. */
116 case 3:
117 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))
118 return FALSE;
119 /* Fall through. */
120 case 2:
121 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))
122 return FALSE;
123 /* Fall through. */
124 case 1:
125 if (! ieee_write_byte (abfd, (bfd_byte) (value)))
126 return FALSE;
127 }
128 }
129
130 return TRUE;
131 }
132
133 static bfd_boolean
134 ieee_write_id (bfd *abfd, const char *id)
135 {
136 size_t length = strlen (id);
137
138 if (length <= 127)
139 {
140 if (! ieee_write_byte (abfd, (bfd_byte) length))
141 return FALSE;
142 }
143 else if (length < 255)
144 {
145 if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)
146 || ! ieee_write_byte (abfd, (bfd_byte) length))
147 return FALSE;
148 }
149 else if (length < 65535)
150 {
151 if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)
152 || ! ieee_write_2bytes (abfd, (int) length))
153 return FALSE;
154 }
155 else
156 {
157 _bfd_error_handler
158 /* xgettext:c-format */
159 (_("%B: string too long (%d chars, max 65535)"), abfd, length);
160 bfd_set_error (bfd_error_invalid_operation);
161 return FALSE;
162 }
163
164 if (bfd_bwrite ((void *) id, (bfd_size_type) length, abfd) != length)
165 return FALSE;
166 return TRUE;
167 }
168 \f
169 /* Functions for reading from ieee files in the strange way that the
170 standard requires. */
171
172 #define this_byte(ieee) *((ieee)->input_p)
173 #define this_byte_and_next(ieee) ((ieee)->input_p < (ieee)->end_p ? *((ieee)->input_p++) : 0)
174
175 static bfd_boolean
176 next_byte (common_header_type * ieee)
177 {
178 ieee->input_p++;
179
180 return ieee->input_p < ieee->last_byte;
181 }
182
183 static unsigned short
184 read_2bytes (common_header_type *ieee)
185 {
186 unsigned char c1 = this_byte_and_next (ieee);
187 unsigned char c2 = this_byte_and_next (ieee);
188
189 return (c1 << 8) | c2;
190 }
191
192 static void
193 bfd_get_string (common_header_type *ieee, char *string, size_t length)
194 {
195 size_t i;
196
197 for (i = 0; i < length; i++)
198 string[i] = this_byte_and_next (ieee);
199 }
200
201 static char *
202 read_id (common_header_type *ieee)
203 {
204 size_t length;
205 char *string;
206
207 length = this_byte_and_next (ieee);
208 if (length <= 0x7f)
209 /* Simple string of length 0 to 127. */
210 ;
211
212 else if (length == 0xde)
213 /* Length is next byte, allowing 0..255. */
214 length = this_byte_and_next (ieee);
215
216 else if (length == 0xdf)
217 {
218 /* Length is next two bytes, allowing 0..65535. */
219 length = this_byte_and_next (ieee);
220 length = (length * 256) + this_byte_and_next (ieee);
221 }
222
223 /* PR 21612: Check for an invalid length. */
224 if (ieee->input_p + length >= ieee->end_p)
225 {
226 _bfd_error_handler (_("IEEE parser: string length: %#lx longer than buffer: %#lx"),
227 length, (long) (ieee->end_p - ieee->input_p));
228 bfd_set_error (bfd_error_invalid_operation);
229 return NULL;
230 }
231
232 /* Buy memory and read string. */
233 string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
234 if (!string)
235 return NULL;
236 bfd_get_string (ieee, string, length);
237 string[length] = 0;
238 return string;
239 }
240
241 static bfd_boolean
242 ieee_write_expression (bfd *abfd,
243 bfd_vma value,
244 asymbol *symbol,
245 bfd_boolean pcrel,
246 unsigned int sindex)
247 {
248 unsigned int term_count = 0;
249
250 if (value != 0)
251 {
252 if (! ieee_write_int (abfd, value))
253 return FALSE;
254 term_count++;
255 }
256
257 /* Badly formatted binaries can have a missing symbol,
258 so test here to prevent a seg fault. */
259 if (symbol != NULL)
260 {
261 if (bfd_is_com_section (symbol->section)
262 || bfd_is_und_section (symbol->section))
263 {
264 /* Def of a common symbol. */
265 if (! ieee_write_byte (abfd, ieee_variable_X_enum)
266 || ! ieee_write_int (abfd, symbol->value))
267 return FALSE;
268 term_count ++;
269 }
270 else if (! bfd_is_abs_section (symbol->section))
271 {
272 /* Ref to defined symbol - */
273 if (symbol->flags & BSF_GLOBAL)
274 {
275 if (! ieee_write_byte (abfd, ieee_variable_I_enum)
276 || ! ieee_write_int (abfd, symbol->value))
277 return FALSE;
278 term_count++;
279 }
280 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
281 {
282 /* This is a reference to a defined local symbol. We can
283 easily do a local as a section+offset. */
284 if (! ieee_write_byte (abfd, ieee_variable_R_enum)
285 || ! ieee_write_byte (abfd,
286 (bfd_byte) (symbol->section->index
287 + IEEE_SECTION_NUMBER_BASE)))
288 return FALSE;
289
290 term_count++;
291 if (symbol->value != 0)
292 {
293 if (! ieee_write_int (abfd, symbol->value))
294 return FALSE;
295 term_count++;
296 }
297 }
298 else
299 {
300 _bfd_error_handler
301 /* xgettext:c-format */
302 (_("%B: unrecognized symbol `%s' flags 0x%x"),
303 abfd, bfd_asymbol_name (symbol), symbol->flags);
304 bfd_set_error (bfd_error_invalid_operation);
305 return FALSE;
306 }
307 }
308 }
309
310 if (pcrel)
311 {
312 /* Subtract the pc from here by asking for PC of this section. */
313 if (! ieee_write_byte (abfd, ieee_variable_P_enum)
314 || ! ieee_write_byte (abfd,
315 (bfd_byte) (sindex + IEEE_SECTION_NUMBER_BASE))
316 || ! ieee_write_byte (abfd, ieee_function_minus_enum))
317 return FALSE;
318 }
319
320 /* Handle the degenerate case of a 0 address. */
321 if (term_count == 0)
322 if (! ieee_write_int (abfd, (bfd_vma) 0))
323 return FALSE;
324
325 while (term_count > 1)
326 {
327 if (! ieee_write_byte (abfd, ieee_function_plus_enum))
328 return FALSE;
329 term_count--;
330 }
331
332 return TRUE;
333 }
334 \f
335 /* Writes any integer into the buffer supplied and always takes 5 bytes. */
336
337 static void
338 ieee_write_int5 (bfd_byte *buffer, bfd_vma value)
339 {
340 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
341 buffer[1] = (value >> 24) & 0xff;
342 buffer[2] = (value >> 16) & 0xff;
343 buffer[3] = (value >> 8) & 0xff;
344 buffer[4] = (value >> 0) & 0xff;
345 }
346
347 static bfd_boolean
348 ieee_write_int5_out (bfd *abfd, bfd_vma value)
349 {
350 bfd_byte b[5];
351
352 ieee_write_int5 (b, value);
353 if (bfd_bwrite ((void *) b, (bfd_size_type) 5, abfd) != 5)
354 return FALSE;
355 return TRUE;
356 }
357
358 static bfd_boolean
359 parse_int (common_header_type *ieee, bfd_vma *value_ptr)
360 {
361 int value = this_byte (ieee);
362 int result;
363
364 if (value >= 0 && value <= 127)
365 {
366 *value_ptr = value;
367 return next_byte (ieee);
368 }
369 else if (value >= 0x80 && value <= 0x88)
370 {
371 unsigned int count = value & 0xf;
372
373 result = 0;
374 if (! next_byte (ieee))
375 return FALSE;
376 while (count)
377 {
378 result = (result << 8) | this_byte_and_next (ieee);
379 count--;
380 }
381 *value_ptr = result;
382 return TRUE;
383 }
384 return FALSE;
385 }
386
387 static int
388 parse_i (common_header_type *ieee, bfd_boolean *ok)
389 {
390 bfd_vma x = 0;
391 *ok = parse_int (ieee, &x);
392 return x;
393 }
394
395 static bfd_vma
396 must_parse_int (common_header_type *ieee)
397 {
398 bfd_vma result = 0;
399 BFD_ASSERT (parse_int (ieee, &result));
400 return result;
401 }
402
403 typedef struct
404 {
405 bfd_vma value;
406 asection *section;
407 ieee_symbol_index_type symbol;
408 } ieee_value_type;
409
410
411 #if KEEPMINUSPCININST
412
413 #define SRC_MASK(arg) arg
414 #define PCREL_OFFSET FALSE
415
416 #else
417
418 #define SRC_MASK(arg) 0
419 #define PCREL_OFFSET TRUE
420
421 #endif
422
423 static reloc_howto_type abs32_howto =
424 HOWTO (1,
425 0,
426 2,
427 32,
428 FALSE,
429 0,
430 complain_overflow_bitfield,
431 0,
432 "abs32",
433 TRUE,
434 0xffffffff,
435 0xffffffff,
436 FALSE);
437
438 static reloc_howto_type abs16_howto =
439 HOWTO (1,
440 0,
441 1,
442 16,
443 FALSE,
444 0,
445 complain_overflow_bitfield,
446 0,
447 "abs16",
448 TRUE,
449 0x0000ffff,
450 0x0000ffff,
451 FALSE);
452
453 static reloc_howto_type abs8_howto =
454 HOWTO (1,
455 0,
456 0,
457 8,
458 FALSE,
459 0,
460 complain_overflow_bitfield,
461 0,
462 "abs8",
463 TRUE,
464 0x000000ff,
465 0x000000ff,
466 FALSE);
467
468 static reloc_howto_type rel32_howto =
469 HOWTO (1,
470 0,
471 2,
472 32,
473 TRUE,
474 0,
475 complain_overflow_signed,
476 0,
477 "rel32",
478 TRUE,
479 SRC_MASK (0xffffffff),
480 0xffffffff,
481 PCREL_OFFSET);
482
483 static reloc_howto_type rel16_howto =
484 HOWTO (1,
485 0,
486 1,
487 16,
488 TRUE,
489 0,
490 complain_overflow_signed,
491 0,
492 "rel16",
493 TRUE,
494 SRC_MASK (0x0000ffff),
495 0x0000ffff,
496 PCREL_OFFSET);
497
498 static reloc_howto_type rel8_howto =
499 HOWTO (1,
500 0,
501 0,
502 8,
503 TRUE,
504 0,
505 complain_overflow_signed,
506 0,
507 "rel8",
508 TRUE,
509 SRC_MASK (0x000000ff),
510 0x000000ff,
511 PCREL_OFFSET);
512
513 static ieee_symbol_index_type NOSYMBOL = {0, 0};
514
515 static bfd_boolean
516 parse_expression (ieee_data_type *ieee,
517 bfd_vma *value,
518 ieee_symbol_index_type *symbol,
519 bfd_boolean *pcrel,
520 unsigned int *extra,
521 asection **section)
522
523 {
524 bfd_boolean loop = TRUE;
525 ieee_value_type stack[10];
526 ieee_value_type *sp = stack;
527 asection *dummy;
528
529 #define POS sp[1]
530 #define TOS sp[0]
531 #define NOS sp[-1]
532 #define INC sp++;
533 #define DEC sp--;
534
535 /* The stack pointer always points to the next unused location. */
536 #define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC;
537 #define POP(x,y,z) DEC; x = TOS.symbol; y = TOS.section; z = TOS.value;
538
539 while (loop && ieee->h.input_p < ieee->h.last_byte)
540 {
541 switch (this_byte (&(ieee->h)))
542 {
543 case ieee_variable_P_enum:
544 /* P variable, current program counter for section n. */
545 {
546 int section_n;
547
548 if (! next_byte (&(ieee->h)))
549 return FALSE;
550 *pcrel = TRUE;
551 section_n = must_parse_int (&(ieee->h));
552 (void) section_n;
553 PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
554 break;
555 }
556
557 case ieee_variable_L_enum:
558 /* L variable address of section N. */
559 if (! next_byte (&(ieee->h)))
560 return FALSE;
561 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
562 break;
563
564 case ieee_variable_R_enum:
565 /* R variable, logical address of section module. */
566 /* FIXME, this should be different to L. */
567 if (! next_byte (&(ieee->h)))
568 return FALSE;
569 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
570 break;
571
572 case ieee_variable_S_enum:
573 /* S variable, size in MAUS of section module. */
574 if (! next_byte (&(ieee->h)))
575 return FALSE;
576 PUSH (NOSYMBOL,
577 0,
578 ieee->section_table[must_parse_int (&(ieee->h))]->size);
579 break;
580
581 case ieee_variable_I_enum:
582 /* Push the address of variable n. */
583 {
584 ieee_symbol_index_type sy;
585
586 if (! next_byte (&(ieee->h)))
587 return FALSE;
588 sy.index = (int) must_parse_int (&(ieee->h));
589 sy.letter = 'I';
590
591 PUSH (sy, bfd_abs_section_ptr, 0);
592 }
593 break;
594
595 case ieee_variable_X_enum:
596 /* Push the address of external variable n. */
597 {
598 ieee_symbol_index_type sy;
599
600 if (! next_byte (&(ieee->h)))
601 return FALSE;
602
603 sy.index = (int) (must_parse_int (&(ieee->h)));
604 sy.letter = 'X';
605
606 PUSH (sy, bfd_und_section_ptr, 0);
607 }
608 break;
609
610 case ieee_function_minus_enum:
611 {
612 bfd_vma value1, value2;
613 asection *section1, *section_dummy;
614 ieee_symbol_index_type sy;
615
616 if (! next_byte (&(ieee->h)))
617 return FALSE;
618
619 POP (sy, section1, value1);
620 POP (sy, section_dummy, value2);
621 PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
622 }
623 break;
624
625 case ieee_function_plus_enum:
626 {
627 bfd_vma value1, value2;
628 asection *section1;
629 asection *section2;
630 ieee_symbol_index_type sy1;
631 ieee_symbol_index_type sy2;
632
633 if (! next_byte (&(ieee->h)))
634 return FALSE;
635
636 POP (sy1, section1, value1);
637 POP (sy2, section2, value2);
638 PUSH (sy1.letter ? sy1 : sy2,
639 bfd_is_abs_section (section1) ? section2 : section1,
640 value1 + value2);
641 }
642 break;
643
644 default:
645 {
646 bfd_vma va;
647
648 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
649 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
650 if (parse_int (&(ieee->h), &va))
651 {
652 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
653 }
654 else
655 /* Thats all that we can understand. */
656 loop = FALSE;
657 }
658 }
659 }
660
661 /* As far as I can see there is a bug in the Microtec IEEE output
662 which I'm using to scan, whereby the comma operator is omitted
663 sometimes in an expression, giving expressions with too many
664 terms. We can tell if that's the case by ensuring that
665 sp == stack here. If not, then we've pushed something too far,
666 so we keep adding. */
667 while (sp != stack + 1)
668 {
669 asection *section1;
670 ieee_symbol_index_type sy1;
671
672 POP (sy1, section1, *extra);
673 (void) section1;
674 (void) sy1;
675 }
676
677 POP (*symbol, dummy, *value);
678 if (section)
679 *section = dummy;
680
681 return TRUE;
682 }
683
684 #define ieee_pos(ieee) \
685 (ieee->h.input_p - ieee->h.first_byte)
686
687 /* Find the first part of the ieee file after HERE. */
688
689 static file_ptr
690 ieee_part_after (ieee_data_type *ieee, file_ptr here)
691 {
692 int part;
693 file_ptr after = ieee->w.r.me_record;
694
695 /* File parts can come in any order, except that module end is
696 guaranteed to be last (and the header first). */
697 for (part = 0; part < N_W_VARIABLES; part++)
698 if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
699 after = ieee->w.offset[part];
700
701 return after;
702 }
703
704 static bfd_boolean
705 ieee_seek (ieee_data_type * ieee, file_ptr offset)
706 {
707 /* PR 17512: file: 017-1157-0.004. */
708 if (offset < 0 || (bfd_size_type) offset >= ieee->h.total_amt)
709 {
710 ieee->h.input_p = ieee->h.first_byte + ieee->h.total_amt;
711 ieee->h.end_p = ieee->h.last_byte = ieee->h.input_p;
712 return FALSE;
713 }
714
715 ieee->h.input_p = ieee->h.first_byte + offset;
716 ieee->h.end_p = ieee->h.last_byte = (ieee->h.first_byte + ieee_part_after (ieee, offset));
717 return TRUE;
718 }
719
720 static unsigned int last_index;
721 static char last_type; /* Is the index for an X or a D. */
722
723 static ieee_symbol_type *
724 get_symbol (bfd *abfd ATTRIBUTE_UNUSED,
725 ieee_data_type *ieee,
726 ieee_symbol_type *last_symbol,
727 unsigned int *symbol_count,
728 ieee_symbol_type ***pptr,
729 unsigned int *max_index,
730 int this_type)
731 {
732 /* Need a new symbol. */
733 unsigned int new_index = must_parse_int (&(ieee->h));
734
735 if (new_index != last_index || this_type != last_type)
736 {
737 ieee_symbol_type *new_symbol;
738 bfd_size_type amt = sizeof (ieee_symbol_type);
739
740 new_symbol = bfd_alloc (ieee->h.abfd, amt);
741 if (!new_symbol)
742 return NULL;
743
744 new_symbol->index = new_index;
745 last_index = new_index;
746 (*symbol_count)++;
747 **pptr = new_symbol;
748 *pptr = &new_symbol->next;
749 if (new_index > *max_index)
750 *max_index = new_index;
751
752 last_type = this_type;
753 new_symbol->symbol.section = bfd_abs_section_ptr;
754 return new_symbol;
755 }
756 return last_symbol;
757 }
758
759 static bfd_boolean
760 ieee_slurp_external_symbols (bfd *abfd)
761 {
762 ieee_data_type *ieee = IEEE_DATA (abfd);
763 file_ptr offset = ieee->w.r.external_part;
764
765 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
766 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
767 ieee_symbol_type *symbol = NULL;
768 unsigned int symbol_count = 0;
769 bfd_boolean loop = TRUE;
770
771 last_index = 0xffffff;
772 ieee->symbol_table_full = TRUE;
773
774 if (! ieee_seek (ieee, offset))
775 return FALSE;
776
777 while (loop)
778 {
779 switch (this_byte (&(ieee->h)))
780 {
781 case ieee_nn_record:
782 if (! next_byte (&(ieee->h)))
783 return FALSE;
784
785 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
786 & prev_symbols_ptr,
787 & ieee->external_symbol_max_index, 'I');
788 if (symbol == NULL)
789 return FALSE;
790
791 symbol->symbol.the_bfd = abfd;
792 symbol->symbol.name = read_id (&(ieee->h));
793 symbol->symbol.udata.p = NULL;
794 symbol->symbol.flags = BSF_NO_FLAGS;
795 break;
796
797 case ieee_external_symbol_enum:
798 if (! next_byte (&(ieee->h)))
799 return FALSE;
800
801 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
802 &prev_symbols_ptr,
803 &ieee->external_symbol_max_index, 'D');
804 if (symbol == NULL)
805 return FALSE;
806
807 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
808
809 symbol->symbol.the_bfd = abfd;
810 symbol->symbol.name = read_id (&(ieee->h));
811 symbol->symbol.udata.p = NULL;
812 symbol->symbol.flags = BSF_NO_FLAGS;
813 break;
814 case ieee_attribute_record_enum >> 8:
815 {
816 unsigned int symbol_name_index;
817 unsigned int symbol_type_index;
818 unsigned int symbol_attribute_def;
819 bfd_vma value = 0;
820
821 switch (read_2bytes (&ieee->h))
822 {
823 case ieee_attribute_record_enum:
824 symbol_name_index = must_parse_int (&(ieee->h));
825 symbol_type_index = must_parse_int (&(ieee->h));
826 (void) symbol_type_index;
827 symbol_attribute_def = must_parse_int (&(ieee->h));
828 switch (symbol_attribute_def)
829 {
830 case 8:
831 case 19:
832 parse_int (&ieee->h, &value);
833 break;
834 default:
835 _bfd_error_handler
836 /* xgettext:c-format */
837 (_("%B: unimplemented ATI record %u for symbol %u"),
838 abfd, symbol_attribute_def, symbol_name_index);
839 bfd_set_error (bfd_error_bad_value);
840 return FALSE;
841 break;
842 }
843 break;
844 case ieee_external_reference_info_record_enum:
845 /* Skip over ATX record. */
846 parse_int (&(ieee->h), &value);
847 parse_int (&(ieee->h), &value);
848 parse_int (&(ieee->h), &value);
849 parse_int (&(ieee->h), &value);
850 break;
851 case ieee_atn_record_enum:
852 /* We may get call optimization information here,
853 which we just ignore. The format is
854 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */
855 parse_int (&ieee->h, &value);
856 parse_int (&ieee->h, &value);
857 parse_int (&ieee->h, &value);
858 if (value != 0x3f)
859 {
860 _bfd_error_handler
861 /* xgettext:c-format */
862 (_("%B: unexpected ATN type %d in external part"),
863 abfd, (int) value);
864 bfd_set_error (bfd_error_bad_value);
865 return FALSE;
866 }
867 parse_int (&ieee->h, &value);
868 parse_int (&ieee->h, &value);
869 while (value > 0)
870 {
871 bfd_vma val1;
872
873 --value;
874
875 switch (read_2bytes (&ieee->h))
876 {
877 case ieee_asn_record_enum:
878 parse_int (&ieee->h, &val1);
879 parse_int (&ieee->h, &val1);
880 break;
881
882 default:
883 _bfd_error_handler
884 (_("%B: unexpected type after ATN"), abfd);
885 bfd_set_error (bfd_error_bad_value);
886 return FALSE;
887 }
888 }
889 }
890 }
891 break;
892
893 case ieee_value_record_enum >> 8:
894 {
895 unsigned int symbol_name_index;
896 ieee_symbol_index_type symbol_ignore;
897 bfd_boolean pcrel_ignore;
898 unsigned int extra;
899
900 if (! next_byte (&(ieee->h)))
901 return FALSE;
902 if (! next_byte (&(ieee->h)))
903 return FALSE;
904
905 symbol_name_index = must_parse_int (&(ieee->h));
906 (void) symbol_name_index;
907 if (! parse_expression (ieee,
908 &symbol->symbol.value,
909 &symbol_ignore,
910 &pcrel_ignore,
911 &extra,
912 &symbol->symbol.section))
913 return FALSE;
914
915 /* Fully linked IEEE-695 files tend to give every symbol
916 an absolute value. Try to convert that back into a
917 section relative value. FIXME: This won't always to
918 the right thing. */
919 if (bfd_is_abs_section (symbol->symbol.section)
920 && (abfd->flags & HAS_RELOC) == 0)
921 {
922 bfd_vma val;
923 asection *s;
924
925 val = symbol->symbol.value;
926 for (s = abfd->sections; s != NULL; s = s->next)
927 {
928 if (val >= s->vma && val < s->vma + s->size)
929 {
930 symbol->symbol.section = s;
931 symbol->symbol.value -= s->vma;
932 break;
933 }
934 }
935 }
936
937 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
938
939 }
940 break;
941 case ieee_weak_external_reference_enum:
942 {
943 bfd_vma size;
944 bfd_vma value;
945
946 if (! next_byte (&(ieee->h)))
947 return FALSE;
948
949 /* Throw away the external reference index. */
950 (void) must_parse_int (&(ieee->h));
951 /* Fetch the default size if not resolved. */
952 size = must_parse_int (&(ieee->h));
953 /* Fetch the default value if available. */
954 if (! parse_int (&(ieee->h), &value))
955 value = 0;
956 /* This turns into a common. */
957 symbol->symbol.section = bfd_com_section_ptr;
958 symbol->symbol.value = size;
959 }
960 break;
961
962 case ieee_external_reference_enum:
963 if (! next_byte (&(ieee->h)))
964 return FALSE;
965
966 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
967 &prev_reference_ptr,
968 &ieee->external_reference_max_index, 'X');
969 if (symbol == NULL)
970 return FALSE;
971
972 symbol->symbol.the_bfd = abfd;
973 symbol->symbol.name = read_id (&(ieee->h));
974 symbol->symbol.udata.p = NULL;
975 symbol->symbol.section = bfd_und_section_ptr;
976 symbol->symbol.value = (bfd_vma) 0;
977 symbol->symbol.flags = 0;
978
979 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
980 break;
981
982 default:
983 loop = FALSE;
984 }
985 }
986
987 if (ieee->external_symbol_max_index != 0)
988 {
989 ieee->external_symbol_count =
990 ieee->external_symbol_max_index -
991 ieee->external_symbol_min_index + 1;
992 }
993 else
994 ieee->external_symbol_count = 0;
995
996 if (ieee->external_reference_max_index != 0)
997 {
998 ieee->external_reference_count =
999 ieee->external_reference_max_index -
1000 ieee->external_reference_min_index + 1;
1001 }
1002 else
1003 ieee->external_reference_count = 0;
1004
1005 abfd->symcount =
1006 ieee->external_reference_count + ieee->external_symbol_count;
1007
1008 if (symbol_count != abfd->symcount)
1009 /* There are gaps in the table -- */
1010 ieee->symbol_table_full = FALSE;
1011
1012 *prev_symbols_ptr = NULL;
1013 *prev_reference_ptr = NULL;
1014
1015 return TRUE;
1016 }
1017
1018 static bfd_boolean
1019 ieee_slurp_symbol_table (bfd *abfd)
1020 {
1021 if (! IEEE_DATA (abfd)->read_symbols)
1022 {
1023 if (! ieee_slurp_external_symbols (abfd))
1024 return FALSE;
1025 IEEE_DATA (abfd)->read_symbols = TRUE;
1026 }
1027 return TRUE;
1028 }
1029
1030 static long
1031 ieee_get_symtab_upper_bound (bfd *abfd)
1032 {
1033 if (! ieee_slurp_symbol_table (abfd))
1034 return -1;
1035
1036 return (abfd->symcount != 0) ?
1037 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
1038 }
1039
1040 /* Move from our internal lists to the canon table, and insert in
1041 symbol index order. */
1042
1043 extern const bfd_target ieee_vec;
1044
1045 static long
1046 ieee_canonicalize_symtab (bfd *abfd, asymbol **location)
1047 {
1048 ieee_symbol_type *symp;
1049 static bfd dummy_bfd;
1050 static asymbol empty_symbol =
1051 {
1052 &dummy_bfd,
1053 " ieee empty",
1054 (symvalue) 0,
1055 BSF_DEBUGGING,
1056 bfd_abs_section_ptr
1057 #ifdef __STDC__
1058 /* K&R compilers can't initialise unions. */
1059 , { 0 }
1060 #endif
1061 };
1062
1063 if (abfd->symcount)
1064 {
1065 ieee_data_type *ieee = IEEE_DATA (abfd);
1066
1067 dummy_bfd.xvec = &ieee_vec;
1068 if (! ieee_slurp_symbol_table (abfd))
1069 return -1;
1070
1071 if (! ieee->symbol_table_full)
1072 {
1073 /* Arrgh - there are gaps in the table, run through and fill them
1074 up with pointers to a null place. */
1075 unsigned int i;
1076
1077 for (i = 0; i < abfd->symcount; i++)
1078 location[i] = &empty_symbol;
1079 }
1080
1081 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
1082 for (symp = IEEE_DATA (abfd)->external_symbols;
1083 symp != (ieee_symbol_type *) NULL;
1084 symp = symp->next)
1085 /* Place into table at correct index locations. */
1086 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
1087
1088 /* The external refs are indexed in a bit. */
1089 ieee->external_reference_base_offset =
1090 -ieee->external_reference_min_index + ieee->external_symbol_count;
1091
1092 for (symp = IEEE_DATA (abfd)->external_reference;
1093 symp != (ieee_symbol_type *) NULL;
1094 symp = symp->next)
1095 location[symp->index + ieee->external_reference_base_offset] =
1096 &symp->symbol;
1097 }
1098
1099 if (abfd->symcount)
1100 location[abfd->symcount] = (asymbol *) NULL;
1101
1102 return abfd->symcount;
1103 }
1104
1105 static asection *
1106 get_section_entry (bfd *abfd, ieee_data_type *ieee, unsigned int sindex)
1107 {
1108 if (sindex >= ieee->section_table_size)
1109 {
1110 unsigned int c, i;
1111 asection **n;
1112 bfd_size_type amt;
1113
1114 c = ieee->section_table_size;
1115 if (c == 0)
1116 c = 20;
1117 while (c <= sindex)
1118 c *= 2;
1119
1120 amt = c;
1121 amt *= sizeof (asection *);
1122 n = bfd_realloc (ieee->section_table, amt);
1123 if (n == NULL)
1124 return NULL;
1125
1126 for (i = ieee->section_table_size; i < c; i++)
1127 n[i] = NULL;
1128
1129 ieee->section_table = n;
1130 ieee->section_table_size = c;
1131 }
1132
1133 if (ieee->section_table[sindex] == (asection *) NULL)
1134 {
1135 char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
1136 asection *section;
1137
1138 if (!tmp)
1139 return NULL;
1140 sprintf (tmp, " fsec%4d", sindex);
1141 section = bfd_make_section (abfd, tmp);
1142 ieee->section_table[sindex] = section;
1143 section->target_index = sindex;
1144 ieee->section_table[sindex] = section;
1145 }
1146 return ieee->section_table[sindex];
1147 }
1148
1149 static bfd_boolean
1150 ieee_slurp_sections (bfd *abfd)
1151 {
1152 ieee_data_type *ieee = IEEE_DATA (abfd);
1153 file_ptr offset = ieee->w.r.section_part;
1154 char *name;
1155
1156 if (offset != 0)
1157 {
1158 bfd_byte section_type[3];
1159
1160 if (! ieee_seek (ieee, offset))
1161 return FALSE;
1162
1163 while (TRUE)
1164 {
1165 switch (this_byte (&(ieee->h)))
1166 {
1167 case ieee_section_type_enum:
1168 {
1169 asection *section;
1170 unsigned int section_index;
1171
1172 if (! next_byte (&(ieee->h)))
1173 return FALSE;
1174 section_index = must_parse_int (&(ieee->h));
1175
1176 section = get_section_entry (abfd, ieee, section_index);
1177
1178 section_type[0] = this_byte_and_next (&(ieee->h));
1179
1180 /* Set minimal section attributes. Attributes are
1181 extended later, based on section contents. */
1182 switch (section_type[0])
1183 {
1184 case 0xC1:
1185 /* Normal attributes for absolute sections. */
1186 section_type[1] = this_byte (&(ieee->h));
1187 section->flags = SEC_ALLOC;
1188 switch (section_type[1])
1189 {
1190 /* AS Absolute section attributes. */
1191 case 0xD3:
1192 if (! next_byte (&(ieee->h)))
1193 return FALSE;
1194 section_type[2] = this_byte (&(ieee->h));
1195 switch (section_type[2])
1196 {
1197 case 0xD0:
1198 /* Normal code. */
1199 if (! next_byte (&(ieee->h)))
1200 return FALSE;
1201 section->flags |= SEC_CODE;
1202 break;
1203 case 0xC4:
1204 /* Normal data. */
1205 if (! next_byte (&(ieee->h)))
1206 return FALSE;
1207 section->flags |= SEC_DATA;
1208 break;
1209 case 0xD2:
1210 if (! next_byte (&(ieee->h)))
1211 return FALSE;
1212 /* Normal rom data. */
1213 section->flags |= SEC_ROM | SEC_DATA;
1214 break;
1215 default:
1216 break;
1217 }
1218 }
1219 break;
1220
1221 /* Named relocatable sections (type C). */
1222 case 0xC3:
1223 section_type[1] = this_byte (&(ieee->h));
1224 section->flags = SEC_ALLOC;
1225 switch (section_type[1])
1226 {
1227 case 0xD0: /* Normal code (CP). */
1228 if (! next_byte (&(ieee->h)))
1229 return FALSE;
1230 section->flags |= SEC_CODE;
1231 break;
1232 case 0xC4: /* Normal data (CD). */
1233 if (! next_byte (&(ieee->h)))
1234 return FALSE;
1235 section->flags |= SEC_DATA;
1236 break;
1237 case 0xD2: /* Normal rom data (CR). */
1238 if (! next_byte (&(ieee->h)))
1239 return FALSE;
1240 section->flags |= SEC_ROM | SEC_DATA;
1241 break;
1242 default:
1243 break;
1244 }
1245 }
1246
1247 /* Read section name, use it if non empty. */
1248 name = read_id (&ieee->h);
1249 if (name[0])
1250 section->name = name;
1251
1252 /* Skip these fields, which we don't care about. */
1253 {
1254 bfd_vma parent, brother, context;
1255
1256 parse_int (&(ieee->h), &parent);
1257 parse_int (&(ieee->h), &brother);
1258 parse_int (&(ieee->h), &context);
1259 }
1260 }
1261 break;
1262 case ieee_section_alignment_enum:
1263 {
1264 unsigned int section_index;
1265 bfd_vma value;
1266 asection *section;
1267
1268 if (! next_byte (&(ieee->h)))
1269 return FALSE;
1270 section_index = must_parse_int (&ieee->h);
1271 section = get_section_entry (abfd, ieee, section_index);
1272 if (section_index > ieee->section_count)
1273 ieee->section_count = section_index;
1274
1275 section->alignment_power =
1276 bfd_log2 (must_parse_int (&ieee->h));
1277 (void) parse_int (&(ieee->h), &value);
1278 }
1279 break;
1280 case ieee_e2_first_byte_enum:
1281 {
1282 asection *section;
1283 ieee_record_enum_type t;
1284
1285 t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
1286 switch (t)
1287 {
1288 case ieee_section_size_enum:
1289 section = ieee->section_table[must_parse_int (&(ieee->h))];
1290 section->size = must_parse_int (&(ieee->h));
1291 break;
1292 case ieee_physical_region_size_enum:
1293 section = ieee->section_table[must_parse_int (&(ieee->h))];
1294 section->size = must_parse_int (&(ieee->h));
1295 break;
1296 case ieee_region_base_address_enum:
1297 section = ieee->section_table[must_parse_int (&(ieee->h))];
1298 section->vma = must_parse_int (&(ieee->h));
1299 section->lma = section->vma;
1300 break;
1301 case ieee_mau_size_enum:
1302 must_parse_int (&(ieee->h));
1303 must_parse_int (&(ieee->h));
1304 break;
1305 case ieee_m_value_enum:
1306 must_parse_int (&(ieee->h));
1307 must_parse_int (&(ieee->h));
1308 break;
1309 case ieee_section_base_address_enum:
1310 section = ieee->section_table[must_parse_int (&(ieee->h))];
1311 section->vma = must_parse_int (&(ieee->h));
1312 section->lma = section->vma;
1313 break;
1314 case ieee_section_offset_enum:
1315 (void) must_parse_int (&(ieee->h));
1316 (void) must_parse_int (&(ieee->h));
1317 break;
1318 default:
1319 return TRUE;
1320 }
1321 }
1322 break;
1323 default:
1324 return TRUE;
1325 }
1326 }
1327 }
1328
1329 return TRUE;
1330 }
1331
1332 /* Make a section for the debugging information, if any. We don't try
1333 to interpret the debugging information; we just point the section
1334 at the area in the file so that program which understand can dig it
1335 out. */
1336
1337 static bfd_boolean
1338 ieee_slurp_debug (bfd *abfd)
1339 {
1340 ieee_data_type *ieee = IEEE_DATA (abfd);
1341 asection *sec;
1342 file_ptr debug_end;
1343 flagword flags;
1344
1345 if (ieee->w.r.debug_information_part == 0)
1346 return TRUE;
1347
1348 flags = SEC_DEBUGGING | SEC_HAS_CONTENTS;
1349 sec = bfd_make_section_with_flags (abfd, ".debug", flags);
1350 if (sec == NULL)
1351 return FALSE;
1352 sec->filepos = ieee->w.r.debug_information_part;
1353
1354 debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
1355 sec->size = debug_end - ieee->w.r.debug_information_part;
1356
1357 return TRUE;
1358 }
1359 \f
1360 /* Archive stuff. */
1361
1362 static const bfd_target *
1363 ieee_archive_p (bfd *abfd)
1364 {
1365 char *library;
1366 unsigned int i;
1367 static unsigned char buffer[512];
1368 file_ptr buffer_offset = 0;
1369 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1370 ieee_ar_data_type *ieee;
1371 bfd_size_type alc_elts;
1372 ieee_ar_obstack_type *elts = NULL;
1373 bfd_size_type amt = sizeof (ieee_ar_data_type);
1374
1375 abfd->tdata.ieee_ar_data = bfd_alloc (abfd, amt);
1376 if (!abfd->tdata.ieee_ar_data)
1377 goto error_ret_restore;
1378 ieee = IEEE_AR_DATA (abfd);
1379
1380 /* Ignore the return value here. It doesn't matter if we don't read
1381 the entire buffer. We might have a very small ieee file. */
1382 if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0)
1383 goto got_wrong_format_error;
1384
1385 ieee->h.first_byte = buffer;
1386 ieee->h.input_p = buffer;
1387 ieee->h.total_amt = sizeof (buffer);
1388 ieee->h.end_p = buffer + sizeof (buffer);
1389
1390 ieee->h.abfd = abfd;
1391
1392 if (this_byte (&(ieee->h)) != Module_Beginning)
1393 goto got_wrong_format_error;
1394
1395 (void) next_byte (&(ieee->h));
1396
1397 library = read_id (&(ieee->h));
1398 if (strcmp (library, "LIBRARY") != 0)
1399 goto got_wrong_format_error;
1400
1401 /* Throw away the filename. */
1402 read_id (&(ieee->h));
1403
1404 ieee->element_count = 0;
1405 ieee->element_index = 0;
1406
1407 (void) next_byte (&(ieee->h)); /* Drop the ad part. */
1408 must_parse_int (&(ieee->h)); /* And the two dummy numbers. */
1409 must_parse_int (&(ieee->h));
1410
1411 alc_elts = 10;
1412 elts = bfd_malloc (alc_elts * sizeof *elts);
1413 if (elts == NULL)
1414 goto error_return;
1415
1416 /* Read the index of the BB table. */
1417 while (1)
1418 {
1419 int rec;
1420 ieee_ar_obstack_type *t;
1421
1422 rec = read_2bytes (&(ieee->h));
1423 if (rec != (int) ieee_assign_value_to_variable_enum)
1424 break;
1425
1426 if (ieee->element_count >= alc_elts)
1427 {
1428 ieee_ar_obstack_type *n;
1429
1430 alc_elts *= 2;
1431 n = bfd_realloc (elts, alc_elts * sizeof (* elts));
1432 if (n == NULL)
1433 goto error_return;
1434 elts = n;
1435 }
1436
1437 t = &elts[ieee->element_count];
1438 ieee->element_count++;
1439
1440 must_parse_int (&(ieee->h));
1441 t->file_offset = must_parse_int (&(ieee->h));
1442 t->abfd = (bfd *) NULL;
1443
1444 /* Make sure that we don't go over the end of the buffer. */
1445 if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
1446 {
1447 /* Past half way, reseek and reprime. */
1448 buffer_offset += ieee_pos (IEEE_DATA (abfd));
1449 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1450 goto error_return;
1451
1452 /* Again ignore return value of bfd_bread. */
1453 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1454 ieee->h.first_byte = buffer;
1455 ieee->h.input_p = buffer;
1456 ieee->h.total_amt = sizeof (buffer);
1457 ieee->h.end_p = buffer + sizeof (buffer);
1458 }
1459 }
1460
1461 amt = ieee->element_count;
1462 amt *= sizeof *ieee->elements;
1463 ieee->elements = bfd_alloc (abfd, amt);
1464 if (ieee->elements == NULL)
1465 goto error_return;
1466
1467 memcpy (ieee->elements, elts, (size_t) amt);
1468 free (elts);
1469 elts = NULL;
1470
1471 /* Now scan the area again, and replace BB offsets with file offsets. */
1472 for (i = 2; i < ieee->element_count; i++)
1473 {
1474 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1475 goto error_return;
1476
1477 /* Again ignore return value of bfd_bread. */
1478 bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
1479 ieee->h.first_byte = buffer;
1480 ieee->h.input_p = buffer;
1481 ieee->h.total_amt = sizeof (buffer);
1482 ieee->h.end_p = buffer + sizeof (buffer);
1483
1484 (void) next_byte (&(ieee->h)); /* Drop F8. */
1485 if (! next_byte (&(ieee->h))) /* Drop 14. */
1486 goto error_return;
1487 must_parse_int (&(ieee->h)); /* Drop size of block. */
1488
1489 if (must_parse_int (&(ieee->h)) != 0)
1490 /* This object has been deleted. */
1491 ieee->elements[i].file_offset = 0;
1492 else
1493 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
1494 }
1495
1496 /* abfd->has_armap = ;*/
1497
1498 return abfd->xvec;
1499
1500 got_wrong_format_error:
1501 bfd_set_error (bfd_error_wrong_format);
1502 error_return:
1503 if (elts != NULL)
1504 free (elts);
1505 bfd_release (abfd, ieee);
1506 error_ret_restore:
1507 abfd->tdata.ieee_ar_data = save;
1508
1509 return NULL;
1510 }
1511
1512 static bfd_boolean
1513 ieee_mkobject (bfd *abfd)
1514 {
1515 bfd_size_type amt;
1516
1517 output_ptr_start = NULL;
1518 output_ptr = NULL;
1519 output_ptr_end = NULL;
1520 input_ptr_start = NULL;
1521 input_ptr = NULL;
1522 input_ptr_end = NULL;
1523 input_bfd = NULL;
1524 output_bfd = NULL;
1525 output_buffer = 0;
1526 amt = sizeof (ieee_data_type);
1527 abfd->tdata.ieee_data = bfd_zalloc (abfd, amt);
1528 return abfd->tdata.ieee_data != NULL;
1529 }
1530
1531 static bfd_boolean
1532 do_one (ieee_data_type *ieee,
1533 ieee_per_section_type *current_map,
1534 unsigned char *location_ptr,
1535 asection *s,
1536 int iterations)
1537 {
1538 switch (this_byte (&(ieee->h)))
1539 {
1540 case ieee_load_constant_bytes_enum:
1541 {
1542 unsigned int number_of_maus;
1543 unsigned int i;
1544
1545 if (! next_byte (&(ieee->h)))
1546 return FALSE;
1547 number_of_maus = must_parse_int (&(ieee->h));
1548
1549 for (i = 0; i < number_of_maus; i++)
1550 {
1551 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1552 next_byte (&(ieee->h));
1553 }
1554 }
1555 break;
1556
1557 case ieee_load_with_relocation_enum:
1558 {
1559 bfd_boolean loop = TRUE;
1560
1561 if (! next_byte (&(ieee->h)))
1562 return FALSE;
1563 while (loop)
1564 {
1565 switch (this_byte (&(ieee->h)))
1566 {
1567 case ieee_variable_R_enum:
1568
1569 case ieee_function_signed_open_b_enum:
1570 case ieee_function_unsigned_open_b_enum:
1571 case ieee_function_either_open_b_enum:
1572 {
1573 unsigned int extra = 4;
1574 bfd_boolean pcrel = FALSE;
1575 asection *section;
1576 ieee_reloc_type *r;
1577
1578 r = bfd_alloc (ieee->h.abfd, sizeof (* r));
1579 if (!r)
1580 return FALSE;
1581
1582 *(current_map->reloc_tail_ptr) = r;
1583 current_map->reloc_tail_ptr = &r->next;
1584 r->next = (ieee_reloc_type *) NULL;
1585 if (! next_byte (&(ieee->h)))
1586 return FALSE;
1587
1588 r->relent.sym_ptr_ptr = 0;
1589 if (! parse_expression (ieee,
1590 &r->relent.addend,
1591 &r->symbol,
1592 &pcrel, &extra, &section))
1593 return FALSE;
1594
1595 r->relent.address = current_map->pc;
1596 s->flags |= SEC_RELOC;
1597 s->owner->flags |= HAS_RELOC;
1598 s->reloc_count++;
1599 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
1600 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1601
1602 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1603 {
1604 if (! next_byte (&(ieee->h)))
1605 return FALSE;
1606 /* Fetch number of bytes to pad. */
1607 extra = must_parse_int (&(ieee->h));
1608 };
1609
1610 switch (this_byte (&(ieee->h)))
1611 {
1612 case ieee_function_signed_close_b_enum:
1613 if (! next_byte (&(ieee->h)))
1614 return FALSE;
1615 break;
1616 case ieee_function_unsigned_close_b_enum:
1617 if (! next_byte (&(ieee->h)))
1618 return FALSE;
1619 break;
1620 case ieee_function_either_close_b_enum:
1621 if (! next_byte (&(ieee->h)))
1622 return FALSE;
1623 break;
1624 default:
1625 break;
1626 }
1627 /* Build a relocation entry for this type. */
1628 /* If pc rel then stick -ve pc into instruction
1629 and take out of reloc ..
1630
1631 I've changed this. It's all too complicated. I
1632 keep 0 in the instruction now. */
1633
1634 switch (extra)
1635 {
1636 case 0:
1637 case 4:
1638
1639 if (pcrel)
1640 {
1641 #if KEEPMINUSPCININST
1642 bfd_put_32 (ieee->h.abfd, -current_map->pc,
1643 location_ptr + current_map->pc);
1644 r->relent.howto = &rel32_howto;
1645 r->relent.addend -= current_map->pc;
1646 #else
1647 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
1648 current_map->pc);
1649 r->relent.howto = &rel32_howto;
1650 #endif
1651 }
1652 else
1653 {
1654 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
1655 location_ptr + current_map->pc);
1656 r->relent.howto = &abs32_howto;
1657 }
1658 current_map->pc += 4;
1659 break;
1660 case 2:
1661 if (pcrel)
1662 {
1663 #if KEEPMINUSPCININST
1664 bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
1665 location_ptr + current_map->pc);
1666 r->relent.addend -= current_map->pc;
1667 r->relent.howto = &rel16_howto;
1668 #else
1669
1670 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1671 location_ptr + current_map->pc);
1672 r->relent.howto = &rel16_howto;
1673 #endif
1674 }
1675
1676 else
1677 {
1678 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1679 location_ptr + current_map->pc);
1680 r->relent.howto = &abs16_howto;
1681 }
1682 current_map->pc += 2;
1683 break;
1684 case 1:
1685 if (pcrel)
1686 {
1687 #if KEEPMINUSPCININST
1688 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1689 r->relent.addend -= current_map->pc;
1690 r->relent.howto = &rel8_howto;
1691 #else
1692 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1693 r->relent.howto = &rel8_howto;
1694 #endif
1695 }
1696 else
1697 {
1698 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1699 r->relent.howto = &abs8_howto;
1700 }
1701 current_map->pc += 1;
1702 break;
1703
1704 default:
1705 BFD_FAIL ();
1706 return FALSE;
1707 }
1708 }
1709 break;
1710 default:
1711 {
1712 bfd_vma this_size;
1713
1714 if (parse_int (&(ieee->h), &this_size))
1715 {
1716 unsigned int i;
1717
1718 for (i = 0; i < this_size; i++)
1719 {
1720 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1721 if (! next_byte (&(ieee->h)))
1722 return FALSE;
1723 }
1724 }
1725 else
1726 loop = FALSE;
1727 }
1728 }
1729
1730 /* Prevent more than the first load-item of an LR record
1731 from being repeated (MRI convention). */
1732 if (iterations != 1)
1733 loop = FALSE;
1734 }
1735 }
1736 }
1737 return TRUE;
1738 }
1739
1740 /* Read in all the section data and relocation stuff too. */
1741
1742 static bfd_boolean
1743 ieee_slurp_section_data (bfd *abfd)
1744 {
1745 bfd_byte *location_ptr = (bfd_byte *) NULL;
1746 ieee_data_type *ieee = IEEE_DATA (abfd);
1747 unsigned int section_number;
1748 ieee_per_section_type *current_map = NULL;
1749 asection *s;
1750
1751 /* Seek to the start of the data area. */
1752 if (ieee->read_data)
1753 return TRUE;
1754 ieee->read_data = TRUE;
1755
1756 if (! ieee_seek (ieee, ieee->w.r.data_part))
1757 return FALSE;
1758
1759 /* Allocate enough space for all the section contents. */
1760 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1761 {
1762 ieee_per_section_type *per = ieee_per_section (s);
1763 arelent **relpp;
1764
1765 if ((s->flags & SEC_DEBUGGING) != 0)
1766 continue;
1767 per->data = bfd_alloc (ieee->h.abfd, s->size);
1768 if (!per->data)
1769 return FALSE;
1770 relpp = &s->relocation;
1771 per->reloc_tail_ptr = (ieee_reloc_type **) relpp;
1772 }
1773
1774 while (TRUE)
1775 {
1776 switch (this_byte (&(ieee->h)))
1777 {
1778 /* IF we see anything strange then quit. */
1779 default:
1780 return TRUE;
1781
1782 case ieee_set_current_section_enum:
1783 if (! next_byte (&(ieee->h)))
1784 return FALSE;
1785 section_number = must_parse_int (&(ieee->h));
1786 s = ieee->section_table[section_number];
1787 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
1788 current_map = ieee_per_section (s);
1789 location_ptr = current_map->data - s->vma;
1790 /* The document I have says that Microtec's compilers reset
1791 this after a sec section, even though the standard says not
1792 to, SO... */
1793 current_map->pc = s->vma;
1794 break;
1795
1796 case ieee_e2_first_byte_enum:
1797 if (! next_byte (&(ieee->h)))
1798 return FALSE;
1799 switch (this_byte (&(ieee->h)))
1800 {
1801 case ieee_set_current_pc_enum & 0xff:
1802 {
1803 bfd_vma value;
1804 ieee_symbol_index_type symbol;
1805 unsigned int extra;
1806 bfd_boolean pcrel;
1807
1808 if (! next_byte (&(ieee->h)))
1809 return FALSE;
1810 must_parse_int (&(ieee->h)); /* Throw away section #. */
1811 if (! parse_expression (ieee, &value,
1812 &symbol,
1813 &pcrel, &extra,
1814 0))
1815 return FALSE;
1816
1817 current_map->pc = value;
1818 BFD_ASSERT ((unsigned) (value - s->vma) <= s->size);
1819 }
1820 break;
1821
1822 case ieee_value_starting_address_enum & 0xff:
1823 if (! next_byte (&(ieee->h)))
1824 return FALSE;
1825 if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
1826 {
1827 if (! next_byte (&(ieee->h)))
1828 return FALSE;
1829 }
1830 abfd->start_address = must_parse_int (&(ieee->h));
1831 /* We've got to the end of the data now - */
1832 return TRUE;
1833 default:
1834 BFD_FAIL ();
1835 return FALSE;
1836 }
1837 break;
1838 case ieee_repeat_data_enum:
1839 {
1840 /* Repeat the following LD or LR n times - we do this by
1841 remembering the stream pointer before running it and
1842 resetting it and running it n times. We special case
1843 the repetition of a repeat_data/load_constant. */
1844 unsigned int iterations;
1845 unsigned char *start;
1846
1847 if (! next_byte (&(ieee->h)))
1848 return FALSE;
1849 iterations = must_parse_int (&(ieee->h));
1850 start = ieee->h.input_p;
1851 if (start[0] == (int) ieee_load_constant_bytes_enum
1852 && start[1] == 1)
1853 {
1854 while (iterations != 0)
1855 {
1856 location_ptr[current_map->pc++] = start[2];
1857 iterations--;
1858 }
1859 (void) next_byte (&(ieee->h));
1860 (void) next_byte (&(ieee->h));
1861 if (! next_byte (&(ieee->h)))
1862 return FALSE;
1863 }
1864 else
1865 {
1866 while (iterations != 0)
1867 {
1868 ieee->h.input_p = start;
1869 if (!do_one (ieee, current_map, location_ptr, s,
1870 (int) iterations))
1871 return FALSE;
1872 iterations--;
1873 }
1874 }
1875 }
1876 break;
1877 case ieee_load_constant_bytes_enum:
1878 case ieee_load_with_relocation_enum:
1879 if (!do_one (ieee, current_map, location_ptr, s, 1))
1880 return FALSE;
1881 }
1882 }
1883 }
1884
1885 static const bfd_target *
1886 ieee_object_p (bfd *abfd)
1887 {
1888 char *processor;
1889 unsigned int part;
1890 ieee_data_type *ieee;
1891 static unsigned char buffer[300];
1892 ieee_data_type *save = IEEE_DATA (abfd);
1893 bfd_size_type amt;
1894
1895 abfd->tdata.ieee_data = 0;
1896 ieee_mkobject (abfd);
1897
1898 ieee = IEEE_DATA (abfd);
1899 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1900 goto fail;
1901 /* Read the first few bytes in to see if it makes sense. Ignore
1902 bfd_bread return value; The file might be very small. */
1903 if (bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd) <= 0)
1904 goto got_wrong_format;
1905
1906 ieee->h.input_p = buffer;
1907 ieee->h.total_amt = sizeof (buffer);
1908 ieee->h.end_p = buffer + sizeof (buffer);
1909
1910 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1911 goto got_wrong_format;
1912
1913 ieee->read_symbols = FALSE;
1914 ieee->read_data = FALSE;
1915 ieee->section_count = 0;
1916 ieee->external_symbol_max_index = 0;
1917 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1918 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1919 ieee->external_reference_max_index = 0;
1920 ieee->h.abfd = abfd;
1921 ieee->section_table = NULL;
1922 ieee->section_table_size = 0;
1923
1924 processor = ieee->mb.processor = read_id (&(ieee->h));
1925 if (strcmp (processor, "LIBRARY") == 0)
1926 goto got_wrong_format;
1927 ieee->mb.module_name = read_id (&(ieee->h));
1928 if (abfd->filename == (const char *) NULL)
1929 abfd->filename = xstrdup (ieee->mb.module_name);
1930
1931 /* Determine the architecture and machine type of the object file. */
1932 {
1933 const bfd_arch_info_type *arch;
1934 char family[10];
1935
1936 /* IEEE does not specify the format of the processor identification
1937 string, so the compiler is free to put in it whatever it wants.
1938 We try here to recognize different processors belonging to the
1939 m68k family. Code for other processors can be added here. */
1940 if ((processor[0] == '6') && (processor[1] == '8'))
1941 {
1942 if (processor[2] == '3') /* 683xx integrated processors. */
1943 {
1944 switch (processor[3])
1945 {
1946 case '0': /* 68302, 68306, 68307 */
1947 case '2': /* 68322, 68328 */
1948 case '5': /* 68356 */
1949 strcpy (family, "68000"); /* MC68000-based controllers. */
1950 break;
1951
1952 case '3': /* 68330, 68331, 68332, 68333,
1953 68334, 68335, 68336, 68338 */
1954 case '6': /* 68360 */
1955 case '7': /* 68376 */
1956 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1957 break;
1958
1959 case '4':
1960 if (processor[4] == '9') /* 68349 */
1961 strcpy (family, "68030"); /* CPU030 */
1962 else /* 68340, 68341 */
1963 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1964 break;
1965
1966 default: /* Does not exist yet. */
1967 strcpy (family, "68332"); /* Guess it will be CPU32 */
1968 }
1969 }
1970 else if (TOUPPER (processor[3]) == 'F') /* 68F333 */
1971 strcpy (family, "68332"); /* CPU32 */
1972 else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers. */
1973 && ((TOUPPER (processor[2]) == 'E')
1974 || (TOUPPER (processor[2]) == 'H')
1975 || (TOUPPER (processor[2]) == 'L')))
1976 {
1977 strcpy (family, "68");
1978 strncat (family, processor + 4, 7);
1979 family[9] = '\0';
1980 }
1981 else /* "Regular" processors. */
1982 {
1983 strncpy (family, processor, 9);
1984 family[9] = '\0';
1985 }
1986 }
1987 else if ((CONST_STRNEQ (processor, "cpu32")) /* CPU32 and CPU32+ */
1988 || (CONST_STRNEQ (processor, "CPU32")))
1989 strcpy (family, "68332");
1990 else
1991 {
1992 strncpy (family, processor, 9);
1993 family[9] = '\0';
1994 }
1995
1996 arch = bfd_scan_arch (family);
1997 if (arch == 0)
1998 goto got_wrong_format;
1999 abfd->arch_info = arch;
2000 }
2001
2002 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
2003 goto fail;
2004
2005 if (! next_byte (&(ieee->h)))
2006 goto fail;
2007
2008 if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
2009 goto fail;
2010
2011 if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
2012 goto fail;
2013
2014 /* If there is a byte order info, take it. */
2015 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum
2016 || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
2017 {
2018 if (! next_byte (&(ieee->h)))
2019 goto fail;
2020 }
2021
2022 for (part = 0; part < N_W_VARIABLES; part++)
2023 {
2024 bfd_boolean ok;
2025
2026 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
2027 goto fail;
2028
2029 if (this_byte_and_next (&(ieee->h)) != part)
2030 goto fail;
2031
2032 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
2033 if (! ok)
2034 goto fail;
2035 }
2036
2037 if (ieee->w.r.external_part != 0)
2038 abfd->flags = HAS_SYMS;
2039
2040 /* By now we know that this is a real IEEE file, we're going to read
2041 the whole thing into memory so that we can run up and down it
2042 quickly. We can work out how big the file is from the trailer
2043 record. */
2044
2045 amt = ieee->w.r.me_record + 1;
2046 IEEE_DATA (abfd)->h.first_byte = bfd_alloc (ieee->h.abfd, amt);
2047 if (!IEEE_DATA (abfd)->h.first_byte)
2048 goto fail;
2049 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
2050 goto fail;
2051
2052 /* FIXME: Check return value. I'm not sure whether it needs to read
2053 the entire buffer or not. */
2054 amt = bfd_bread ((void *) (IEEE_DATA (abfd)->h.first_byte),
2055 (bfd_size_type) ieee->w.r.me_record + 1, abfd);
2056 if (amt <= 0)
2057 goto fail;
2058
2059 IEEE_DATA (abfd)->h.total_amt = amt;
2060 if (ieee_slurp_sections (abfd))
2061 goto fail;
2062
2063 if (! ieee_slurp_debug (abfd))
2064 goto fail;
2065
2066 /* Parse section data to activate file and section flags implied by
2067 section contents. */
2068 if (! ieee_slurp_section_data (abfd))
2069 goto fail;
2070
2071 return abfd->xvec;
2072 got_wrong_format:
2073 bfd_set_error (bfd_error_wrong_format);
2074 fail:
2075 bfd_release (abfd, ieee);
2076 abfd->tdata.ieee_data = save;
2077 return (const bfd_target *) NULL;
2078 }
2079
2080 static void
2081 ieee_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED,
2082 asymbol *symbol,
2083 symbol_info *ret)
2084 {
2085 bfd_symbol_info (symbol, ret);
2086 if (symbol->name[0] == ' ')
2087 ret->name = "* empty table entry ";
2088 if (!symbol->section)
2089 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
2090 }
2091
2092 static void
2093 ieee_print_symbol (bfd *abfd,
2094 void * afile,
2095 asymbol *symbol,
2096 bfd_print_symbol_type how)
2097 {
2098 FILE *file = (FILE *) afile;
2099
2100 switch (how)
2101 {
2102 case bfd_print_symbol_name:
2103 fprintf (file, "%s", symbol->name);
2104 break;
2105 case bfd_print_symbol_more:
2106 BFD_FAIL ();
2107 break;
2108 case bfd_print_symbol_all:
2109 {
2110 const char *section_name =
2111 (symbol->section == (asection *) NULL
2112 ? "*abs"
2113 : symbol->section->name);
2114
2115 if (symbol->name[0] == ' ')
2116 fprintf (file, "* empty table entry ");
2117 else
2118 {
2119 bfd_print_symbol_vandf (abfd, (void *) file, symbol);
2120
2121 fprintf (file, " %-5s %04x %02x %s",
2122 section_name,
2123 (unsigned) ieee_symbol (symbol)->index,
2124 (unsigned) 0,
2125 symbol->name);
2126 }
2127 }
2128 break;
2129 }
2130 }
2131
2132 static bfd_boolean
2133 ieee_new_section_hook (bfd *abfd, asection *newsect)
2134 {
2135 if (!newsect->used_by_bfd)
2136 {
2137 newsect->used_by_bfd = bfd_alloc (abfd, sizeof (ieee_per_section_type));
2138 if (!newsect->used_by_bfd)
2139 return FALSE;
2140 }
2141 ieee_per_section (newsect)->data = NULL;
2142 ieee_per_section (newsect)->section = newsect;
2143 return _bfd_generic_new_section_hook (abfd, newsect);
2144 }
2145
2146 static long
2147 ieee_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
2148 {
2149 if ((asect->flags & SEC_DEBUGGING) != 0)
2150 return 0;
2151 if (! ieee_slurp_section_data (abfd))
2152 return -1;
2153 return (asect->reloc_count + 1) * sizeof (arelent *);
2154 }
2155
2156 static bfd_boolean
2157 ieee_get_section_contents (bfd *abfd,
2158 sec_ptr section,
2159 void * location,
2160 file_ptr offset,
2161 bfd_size_type count)
2162 {
2163 ieee_per_section_type *p = ieee_per_section (section);
2164 if ((section->flags & SEC_DEBUGGING) != 0)
2165 return _bfd_generic_get_section_contents (abfd, section, location,
2166 offset, count);
2167 ieee_slurp_section_data (abfd);
2168 (void) memcpy ((void *) location, (void *) (p->data + offset), (unsigned) count);
2169 return TRUE;
2170 }
2171
2172 static long
2173 ieee_canonicalize_reloc (bfd *abfd,
2174 sec_ptr section,
2175 arelent **relptr,
2176 asymbol **symbols)
2177 {
2178 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
2179 ieee_data_type *ieee = IEEE_DATA (abfd);
2180
2181 if ((section->flags & SEC_DEBUGGING) != 0)
2182 return 0;
2183
2184 while (src != (ieee_reloc_type *) NULL)
2185 {
2186 /* Work out which symbol to attach it this reloc to. */
2187 switch (src->symbol.letter)
2188 {
2189 case 'I':
2190 src->relent.sym_ptr_ptr =
2191 symbols + src->symbol.index + ieee->external_symbol_base_offset;
2192 break;
2193 case 'X':
2194 src->relent.sym_ptr_ptr =
2195 symbols + src->symbol.index + ieee->external_reference_base_offset;
2196 break;
2197 case 0:
2198 if (src->relent.sym_ptr_ptr != NULL)
2199 src->relent.sym_ptr_ptr =
2200 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
2201 break;
2202 default:
2203
2204 BFD_FAIL ();
2205 }
2206 *relptr++ = &src->relent;
2207 src = src->next;
2208 }
2209 *relptr = NULL;
2210 return section->reloc_count;
2211 }
2212
2213 static int
2214 comp (const void * ap, const void * bp)
2215 {
2216 arelent *a = *((arelent **) ap);
2217 arelent *b = *((arelent **) bp);
2218 return a->address - b->address;
2219 }
2220
2221 /* Write the section headers. */
2222
2223 static bfd_boolean
2224 ieee_write_section_part (bfd *abfd)
2225 {
2226 ieee_data_type *ieee = IEEE_DATA (abfd);
2227 asection *s;
2228
2229 ieee->w.r.section_part = bfd_tell (abfd);
2230 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2231 {
2232 if (! bfd_is_abs_section (s)
2233 && (s->flags & SEC_DEBUGGING) == 0)
2234 {
2235 if (! ieee_write_byte (abfd, ieee_section_type_enum)
2236 || ! ieee_write_byte (abfd,
2237 (bfd_byte) (s->index
2238 + IEEE_SECTION_NUMBER_BASE)))
2239 return FALSE;
2240
2241 if (abfd->flags & EXEC_P)
2242 {
2243 /* This image is executable, so output absolute sections. */
2244 if (! ieee_write_byte (abfd, ieee_variable_A_enum)
2245 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
2246 return FALSE;
2247 }
2248 else
2249 {
2250 if (! ieee_write_byte (abfd, ieee_variable_C_enum))
2251 return FALSE;
2252 }
2253
2254 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
2255 {
2256 case SEC_CODE | SEC_LOAD:
2257 case SEC_CODE:
2258 if (! ieee_write_byte (abfd, ieee_variable_P_enum))
2259 return FALSE;
2260 break;
2261 case SEC_DATA:
2262 default:
2263 if (! ieee_write_byte (abfd, ieee_variable_D_enum))
2264 return FALSE;
2265 break;
2266 case SEC_ROM:
2267 case SEC_ROM | SEC_DATA:
2268 case SEC_ROM | SEC_LOAD:
2269 case SEC_ROM | SEC_DATA | SEC_LOAD:
2270 if (! ieee_write_byte (abfd, ieee_variable_R_enum))
2271 return FALSE;
2272 }
2273
2274
2275 if (! ieee_write_id (abfd, s->name))
2276 return FALSE;
2277 /* Alignment. */
2278 if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
2279 || ! ieee_write_byte (abfd,
2280 (bfd_byte) (s->index
2281 + IEEE_SECTION_NUMBER_BASE))
2282 || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
2283 return FALSE;
2284
2285 /* Size. */
2286 if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
2287 || ! ieee_write_byte (abfd,
2288 (bfd_byte) (s->index
2289 + IEEE_SECTION_NUMBER_BASE))
2290 || ! ieee_write_int (abfd, s->size))
2291 return FALSE;
2292 if (abfd->flags & EXEC_P)
2293 {
2294 /* Relocateable sections don't have asl records. */
2295 /* Vma. */
2296 if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
2297 || ! ieee_write_byte (abfd,
2298 ((bfd_byte)
2299 (s->index
2300 + IEEE_SECTION_NUMBER_BASE)))
2301 || ! ieee_write_int (abfd, s->lma))
2302 return FALSE;
2303 }
2304 }
2305 }
2306
2307 return TRUE;
2308 }
2309
2310 static bfd_boolean
2311 do_with_relocs (bfd *abfd, asection *s)
2312 {
2313 unsigned int number_of_maus_in_address =
2314 bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
2315 unsigned int relocs_to_go = s->reloc_count;
2316 bfd_byte *stream = ieee_per_section (s)->data;
2317 arelent **p = s->orelocation;
2318 bfd_size_type current_byte_index = 0;
2319
2320 qsort (s->orelocation,
2321 relocs_to_go,
2322 sizeof (arelent **),
2323 comp);
2324
2325 /* Output the section preheader. */
2326 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2327 || ! ieee_write_byte (abfd,
2328 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
2329 || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
2330 || ! ieee_write_byte (abfd,
2331 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
2332 return FALSE;
2333
2334 if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
2335 {
2336 if (! ieee_write_int (abfd, s->lma))
2337 return FALSE;
2338 }
2339 else
2340 {
2341 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2342 return FALSE;
2343 }
2344
2345 if (relocs_to_go == 0)
2346 {
2347 /* If there aren't any relocations then output the load constant
2348 byte opcode rather than the load with relocation opcode. */
2349 while (current_byte_index < s->size)
2350 {
2351 bfd_size_type run;
2352 unsigned int MAXRUN = 127;
2353
2354 run = MAXRUN;
2355 if (run > s->size - current_byte_index)
2356 run = s->size - current_byte_index;
2357
2358 if (run != 0)
2359 {
2360 if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
2361 return FALSE;
2362 /* Output a stream of bytes. */
2363 if (! ieee_write_int (abfd, run))
2364 return FALSE;
2365 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
2366 != run)
2367 return FALSE;
2368 current_byte_index += run;
2369 }
2370 }
2371 }
2372 else
2373 {
2374 if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
2375 return FALSE;
2376
2377 /* Output the data stream as the longest sequence of bytes
2378 possible, allowing for the a reasonable packet size and
2379 relocation stuffs. */
2380 if (stream == NULL)
2381 {
2382 /* Outputting a section without data, fill it up. */
2383 stream = bfd_zalloc (abfd, s->size);
2384 if (!stream)
2385 return FALSE;
2386 }
2387 while (current_byte_index < s->size)
2388 {
2389 bfd_size_type run;
2390 unsigned int MAXRUN = 127;
2391
2392 if (relocs_to_go)
2393 {
2394 run = (*p)->address - current_byte_index;
2395 if (run > MAXRUN)
2396 run = MAXRUN;
2397 }
2398 else
2399 run = MAXRUN;
2400
2401 if (run > s->size - current_byte_index)
2402 run = s->size - current_byte_index;
2403
2404 if (run != 0)
2405 {
2406 /* Output a stream of bytes. */
2407 if (! ieee_write_int (abfd, run))
2408 return FALSE;
2409 if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
2410 != run)
2411 return FALSE;
2412 current_byte_index += run;
2413 }
2414
2415 /* Output any relocations here. */
2416 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
2417 {
2418 while (relocs_to_go
2419 && (*p) && (*p)->address == current_byte_index)
2420 {
2421 arelent *r = *p;
2422 bfd_signed_vma ov;
2423 switch (r->howto->size)
2424 {
2425 case 2:
2426 ov = bfd_get_signed_32 (abfd,
2427 stream + current_byte_index);
2428 current_byte_index += 4;
2429 break;
2430 case 1:
2431 ov = bfd_get_signed_16 (abfd,
2432 stream + current_byte_index);
2433 current_byte_index += 2;
2434 break;
2435 case 0:
2436 ov = bfd_get_signed_8 (abfd,
2437 stream + current_byte_index);
2438 current_byte_index++;
2439 break;
2440 default:
2441 ov = 0;
2442 BFD_FAIL ();
2443 return FALSE;
2444 }
2445
2446 ov &= r->howto->src_mask;
2447
2448 if (r->howto->pc_relative
2449 && ! r->howto->pcrel_offset)
2450 ov += r->address;
2451
2452 if (! ieee_write_byte (abfd,
2453 ieee_function_either_open_b_enum))
2454 return FALSE;
2455
2456 if (r->sym_ptr_ptr != (asymbol **) NULL)
2457 {
2458 if (! ieee_write_expression (abfd, r->addend + ov,
2459 *(r->sym_ptr_ptr),
2460 r->howto->pc_relative,
2461 (unsigned) s->index))
2462 return FALSE;
2463 }
2464 else
2465 {
2466 if (! ieee_write_expression (abfd, r->addend + ov,
2467 (asymbol *) NULL,
2468 r->howto->pc_relative,
2469 (unsigned) s->index))
2470 return FALSE;
2471 }
2472
2473 if (number_of_maus_in_address
2474 != bfd_get_reloc_size (r->howto))
2475 {
2476 bfd_vma rsize = bfd_get_reloc_size (r->howto);
2477 if (! ieee_write_int (abfd, rsize))
2478 return FALSE;
2479 }
2480 if (! ieee_write_byte (abfd,
2481 ieee_function_either_close_b_enum))
2482 return FALSE;
2483
2484 relocs_to_go--;
2485 p++;
2486 }
2487
2488 }
2489 }
2490 }
2491
2492 return TRUE;
2493 }
2494
2495 /* If there are no relocations in the output section then we can be
2496 clever about how we write. We block items up into a max of 127
2497 bytes. */
2498
2499 static bfd_boolean
2500 do_as_repeat (bfd *abfd, asection *s)
2501 {
2502 if (s->size)
2503 {
2504 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2505 || ! ieee_write_byte (abfd,
2506 (bfd_byte) (s->index
2507 + IEEE_SECTION_NUMBER_BASE))
2508 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
2509 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
2510 || ! ieee_write_byte (abfd,
2511 (bfd_byte) (s->index
2512 + IEEE_SECTION_NUMBER_BASE)))
2513 return FALSE;
2514
2515 if ((abfd->flags & EXEC_P) != 0)
2516 {
2517 if (! ieee_write_int (abfd, s->lma))
2518 return FALSE;
2519 }
2520 else
2521 {
2522 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
2523 return FALSE;
2524 }
2525
2526 if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
2527 || ! ieee_write_int (abfd, s->size)
2528 || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
2529 || ! ieee_write_byte (abfd, 1)
2530 || ! ieee_write_byte (abfd, 0))
2531 return FALSE;
2532 }
2533
2534 return TRUE;
2535 }
2536
2537 static bfd_boolean
2538 do_without_relocs (bfd *abfd, asection *s)
2539 {
2540 bfd_byte *stream = ieee_per_section (s)->data;
2541
2542 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2543 {
2544 if (! do_as_repeat (abfd, s))
2545 return FALSE;
2546 }
2547 else
2548 {
2549 unsigned int i;
2550
2551 for (i = 0; i < s->size; i++)
2552 {
2553 if (stream[i] != 0)
2554 {
2555 if (! do_with_relocs (abfd, s))
2556 return FALSE;
2557 return TRUE;
2558 }
2559 }
2560 if (! do_as_repeat (abfd, s))
2561 return FALSE;
2562 }
2563
2564 return TRUE;
2565 }
2566
2567 static void
2568 fill (void)
2569 {
2570 bfd_size_type amt = input_ptr_end - input_ptr_start;
2571 /* FIXME: Check return value. I'm not sure whether it needs to read
2572 the entire buffer or not. */
2573 bfd_bread ((void *) input_ptr_start, amt, input_bfd);
2574 input_ptr = input_ptr_start;
2575 }
2576
2577 static void
2578 flush (void)
2579 {
2580 bfd_size_type amt = output_ptr - output_ptr_start;
2581
2582 if (bfd_bwrite ((void *) (output_ptr_start), amt, output_bfd) != amt)
2583 abort ();
2584 output_ptr = output_ptr_start;
2585 output_buffer++;
2586 }
2587
2588 #define THIS() ( *input_ptr )
2589 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); }
2590 #define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end) flush (); }
2591
2592 static void
2593 write_int (int value)
2594 {
2595 if (value >= 0 && value <= 127)
2596 {
2597 OUT (value);
2598 }
2599 else
2600 {
2601 unsigned int length;
2602
2603 /* How many significant bytes ? */
2604 /* FIXME FOR LONGER INTS. */
2605 if (value & 0xff000000)
2606 length = 4;
2607 else if (value & 0x00ff0000)
2608 length = 3;
2609 else if (value & 0x0000ff00)
2610 length = 2;
2611 else
2612 length = 1;
2613
2614 OUT ((int) ieee_number_repeat_start_enum + length);
2615 switch (length)
2616 {
2617 case 4:
2618 OUT (value >> 24);
2619 /* Fall through. */
2620 case 3:
2621 OUT (value >> 16);
2622 /* Fall through. */
2623 case 2:
2624 OUT (value >> 8);
2625 /* Fall through. */
2626 case 1:
2627 OUT (value);
2628 }
2629 }
2630 }
2631
2632 static void
2633 copy_id (void)
2634 {
2635 int length = THIS ();
2636 char ch;
2637
2638 OUT (length);
2639 NEXT ();
2640 while (length--)
2641 {
2642 ch = THIS ();
2643 OUT (ch);
2644 NEXT ();
2645 }
2646 }
2647
2648 #define VAR(x) ((x | 0x80))
2649 static void
2650 copy_expression (void)
2651 {
2652 int stack[10];
2653 int *tos = stack;
2654 int value;
2655
2656 while (1)
2657 {
2658 switch (THIS ())
2659 {
2660 case 0x84:
2661 NEXT ();
2662 value = THIS ();
2663 NEXT ();
2664 value = (value << 8) | THIS ();
2665 NEXT ();
2666 value = (value << 8) | THIS ();
2667 NEXT ();
2668 value = (value << 8) | THIS ();
2669 NEXT ();
2670 *tos++ = value;
2671 break;
2672 case 0x83:
2673 NEXT ();
2674 value = THIS ();
2675 NEXT ();
2676 value = (value << 8) | THIS ();
2677 NEXT ();
2678 value = (value << 8) | THIS ();
2679 NEXT ();
2680 *tos++ = value;
2681 break;
2682 case 0x82:
2683 NEXT ();
2684 value = THIS ();
2685 NEXT ();
2686 value = (value << 8) | THIS ();
2687 NEXT ();
2688 *tos++ = value;
2689 break;
2690 case 0x81:
2691 NEXT ();
2692 value = THIS ();
2693 NEXT ();
2694 *tos++ = value;
2695 break;
2696 case 0x80:
2697 NEXT ();
2698 *tos++ = 0;
2699 break;
2700 default:
2701 if (THIS () > 0x84)
2702 {
2703 /* Not a number, just bug out with the answer. */
2704 write_int (*(--tos));
2705 return;
2706 }
2707 *tos++ = THIS ();
2708 NEXT ();
2709 break;
2710 case 0xa5:
2711 /* PLUS anything. */
2712 value = *(--tos);
2713 value += *(--tos);
2714 *tos++ = value;
2715 NEXT ();
2716 break;
2717 case VAR ('R'):
2718 {
2719 int section_number;
2720 ieee_data_type *ieee;
2721 asection *s;
2722
2723 NEXT ();
2724 section_number = THIS ();
2725
2726 NEXT ();
2727 ieee = IEEE_DATA (input_bfd);
2728 s = ieee->section_table[section_number];
2729 value = 0;
2730 if (s->output_section)
2731 value = s->output_section->lma;
2732 value += s->output_offset;
2733 *tos++ = value;
2734 }
2735 break;
2736 case 0x90:
2737 {
2738 NEXT ();
2739 write_int (*(--tos));
2740 OUT (0x90);
2741 return;
2742 }
2743 }
2744 }
2745 }
2746
2747 /* Drop the int in the buffer, and copy a null into the gap, which we
2748 will overwrite later. */
2749
2750 static void
2751 fill_int (struct output_buffer_struct *buf)
2752 {
2753 if (buf->buffer == output_buffer)
2754 {
2755 /* Still a chance to output the size. */
2756 int value = output_ptr - buf->ptrp + 3;
2757 buf->ptrp[0] = value >> 24;
2758 buf->ptrp[1] = value >> 16;
2759 buf->ptrp[2] = value >> 8;
2760 buf->ptrp[3] = value >> 0;
2761 }
2762 }
2763
2764 static void
2765 drop_int (struct output_buffer_struct *buf)
2766 {
2767 int type = THIS ();
2768 int ch;
2769
2770 if (type <= 0x84)
2771 {
2772 NEXT ();
2773 switch (type)
2774 {
2775 case 0x84:
2776 ch = THIS ();
2777 NEXT ();
2778 /* Fall through. */
2779 case 0x83:
2780 ch = THIS ();
2781 NEXT ();
2782 /* Fall through. */
2783 case 0x82:
2784 ch = THIS ();
2785 NEXT ();
2786 /* Fall through. */
2787 case 0x81:
2788 ch = THIS ();
2789 NEXT ();
2790 /* Fall through. */
2791 case 0x80:
2792 break;
2793 }
2794 }
2795 (void) ch;
2796 OUT (0x84);
2797 buf->ptrp = output_ptr;
2798 buf->buffer = output_buffer;
2799 OUT (0);
2800 OUT (0);
2801 OUT (0);
2802 OUT (0);
2803 }
2804
2805 static void
2806 copy_int (void)
2807 {
2808 int type = THIS ();
2809 int ch;
2810 if (type <= 0x84)
2811 {
2812 OUT (type);
2813 NEXT ();
2814 switch (type)
2815 {
2816 case 0x84:
2817 ch = THIS ();
2818 NEXT ();
2819 OUT (ch);
2820 /* Fall through. */
2821 case 0x83:
2822 ch = THIS ();
2823 NEXT ();
2824 OUT (ch);
2825 /* Fall through. */
2826 case 0x82:
2827 ch = THIS ();
2828 NEXT ();
2829 OUT (ch);
2830 /* Fall through. */
2831 case 0x81:
2832 ch = THIS ();
2833 NEXT ();
2834 OUT (ch);
2835 /* Fall through. */
2836 case 0x80:
2837 break;
2838 }
2839 }
2840 }
2841
2842 #define ID copy_id ()
2843 #define INT copy_int ()
2844 #define EXP copy_expression ()
2845 #define INTn(q) copy_int ()
2846 #define EXPn(q) copy_expression ()
2847
2848 static void
2849 copy_till_end (void)
2850 {
2851 int ch = THIS ();
2852
2853 while (1)
2854 {
2855 while (ch <= 0x80)
2856 {
2857 OUT (ch);
2858 NEXT ();
2859 ch = THIS ();
2860 }
2861 switch (ch)
2862 {
2863 case 0x84:
2864 OUT (THIS ());
2865 NEXT ();
2866 /* Fall through. */
2867 case 0x83:
2868 OUT (THIS ());
2869 NEXT ();
2870 /* Fall through. */
2871 case 0x82:
2872 OUT (THIS ());
2873 NEXT ();
2874 /* Fall through. */
2875 case 0x81:
2876 OUT (THIS ());
2877 NEXT ();
2878 OUT (THIS ());
2879 NEXT ();
2880
2881 ch = THIS ();
2882 break;
2883 default:
2884 return;
2885 }
2886 }
2887
2888 }
2889
2890 static void
2891 f1_record (void)
2892 {
2893 int ch;
2894
2895 /* ATN record. */
2896 NEXT ();
2897 ch = THIS ();
2898 switch (ch)
2899 {
2900 default:
2901 OUT (0xf1);
2902 OUT (ch);
2903 break;
2904 case 0xc9:
2905 NEXT ();
2906 OUT (0xf1);
2907 OUT (0xc9);
2908 INT;
2909 INT;
2910 ch = THIS ();
2911 switch (ch)
2912 {
2913 case 0x16:
2914 NEXT ();
2915 break;
2916 case 0x01:
2917 NEXT ();
2918 break;
2919 case 0x00:
2920 NEXT ();
2921 INT;
2922 break;
2923 case 0x03:
2924 NEXT ();
2925 INT;
2926 break;
2927 case 0x13:
2928 EXPn (instruction address);
2929 break;
2930 default:
2931 break;
2932 }
2933 break;
2934 case 0xd8:
2935 /* EXternal ref. */
2936 NEXT ();
2937 OUT (0xf1);
2938 OUT (0xd8);
2939 EXP;
2940 EXP;
2941 EXP;
2942 EXP;
2943 break;
2944 case 0xce:
2945 NEXT ();
2946 OUT (0xf1);
2947 OUT (0xce);
2948 INT;
2949 INT;
2950 ch = THIS ();
2951 INT;
2952 switch (ch)
2953 {
2954 case 0x01:
2955 INT;
2956 INT;
2957 break;
2958 case 0x02:
2959 INT;
2960 break;
2961 case 0x04:
2962 EXPn (external function);
2963 break;
2964 case 0x05:
2965 break;
2966 case 0x07:
2967 INTn (line number);
2968 INT;
2969 case 0x08:
2970 break;
2971 case 0x0a:
2972 INTn (locked register);
2973 INT;
2974 break;
2975 case 0x3f:
2976 copy_till_end ();
2977 break;
2978 case 0x3e:
2979 copy_till_end ();
2980 break;
2981 case 0x40:
2982 copy_till_end ();
2983 break;
2984 case 0x41:
2985 ID;
2986 break;
2987 }
2988 }
2989 }
2990
2991 static void
2992 f0_record (void)
2993 {
2994 /* Attribute record. */
2995 NEXT ();
2996 OUT (0xf0);
2997 INTn (Symbol name);
2998 ID;
2999 }
3000
3001 static void
3002 f2_record (void)
3003 {
3004 NEXT ();
3005 OUT (0xf2);
3006 INT;
3007 NEXT ();
3008 OUT (0xce);
3009 INT;
3010 copy_till_end ();
3011 }
3012
3013 static void
3014 f8_record (void)
3015 {
3016 int ch;
3017 NEXT ();
3018 ch = THIS ();
3019 switch (ch)
3020 {
3021 case 0x01:
3022 case 0x02:
3023 case 0x03:
3024 /* Unique typedefs for module. */
3025 /* GLobal typedefs. */
3026 /* High level module scope beginning. */
3027 {
3028 struct output_buffer_struct ob;
3029
3030 NEXT ();
3031 OUT (0xf8);
3032 OUT (ch);
3033 drop_int (&ob);
3034 ID;
3035
3036 block ();
3037
3038 NEXT ();
3039 fill_int (&ob);
3040 OUT (0xf9);
3041 }
3042 break;
3043 case 0x04:
3044 /* Global function. */
3045 {
3046 struct output_buffer_struct ob;
3047
3048 NEXT ();
3049 OUT (0xf8);
3050 OUT (0x04);
3051 drop_int (&ob);
3052 ID;
3053 INTn (stack size);
3054 INTn (ret val);
3055 EXPn (offset);
3056
3057 block ();
3058
3059 NEXT ();
3060 OUT (0xf9);
3061 EXPn (size of block);
3062 fill_int (&ob);
3063 }
3064 break;
3065
3066 case 0x05:
3067 /* File name for source line numbers. */
3068 {
3069 struct output_buffer_struct ob;
3070
3071 NEXT ();
3072 OUT (0xf8);
3073 OUT (0x05);
3074 drop_int (&ob);
3075 ID;
3076 INTn (year);
3077 INTn (month);
3078 INTn (day);
3079 INTn (hour);
3080 INTn (monute);
3081 INTn (second);
3082 block ();
3083 NEXT ();
3084 OUT (0xf9);
3085 fill_int (&ob);
3086 }
3087 break;
3088
3089 case 0x06:
3090 /* Local function. */
3091 {
3092 struct output_buffer_struct ob;
3093
3094 NEXT ();
3095 OUT (0xf8);
3096 OUT (0x06);
3097 drop_int (&ob);
3098 ID;
3099 INTn (stack size);
3100 INTn (type return);
3101 EXPn (offset);
3102 block ();
3103 NEXT ();
3104 OUT (0xf9);
3105 EXPn (size);
3106 fill_int (&ob);
3107 }
3108 break;
3109
3110 case 0x0a:
3111 /* Assembler module scope beginning - */
3112 {
3113 struct output_buffer_struct ob;
3114
3115 NEXT ();
3116 OUT (0xf8);
3117 OUT (0x0a);
3118 drop_int (&ob);
3119 ID;
3120 ID;
3121 INT;
3122 ID;
3123 INT;
3124 INT;
3125 INT;
3126 INT;
3127 INT;
3128 INT;
3129
3130 block ();
3131
3132 NEXT ();
3133 OUT (0xf9);
3134 fill_int (&ob);
3135 }
3136 break;
3137 case 0x0b:
3138 {
3139 struct output_buffer_struct ob;
3140
3141 NEXT ();
3142 OUT (0xf8);
3143 OUT (0x0b);
3144 drop_int (&ob);
3145 ID;
3146 INT;
3147 INTn (section index);
3148 EXPn (offset);
3149 INTn (stuff);
3150
3151 block ();
3152
3153 OUT (0xf9);
3154 NEXT ();
3155 EXPn (Size in Maus);
3156 fill_int (&ob);
3157 }
3158 break;
3159 }
3160 }
3161
3162 static void
3163 e2_record (void)
3164 {
3165 OUT (0xe2);
3166 NEXT ();
3167 OUT (0xce);
3168 NEXT ();
3169 INT;
3170 EXP;
3171 }
3172
3173 static void
3174 block (void)
3175 {
3176 int ch;
3177
3178 while (1)
3179 {
3180 ch = THIS ();
3181 switch (ch)
3182 {
3183 case 0xe1:
3184 case 0xe5:
3185 return;
3186 case 0xf9:
3187 return;
3188 case 0xf0:
3189 f0_record ();
3190 break;
3191 case 0xf1:
3192 f1_record ();
3193 break;
3194 case 0xf2:
3195 f2_record ();
3196 break;
3197 case 0xf8:
3198 f8_record ();
3199 break;
3200 case 0xe2:
3201 e2_record ();
3202 break;
3203
3204 }
3205 }
3206 }
3207
3208 /* Moves all the debug information from the source bfd to the output
3209 bfd, and relocates any expressions it finds. */
3210
3211 static void
3212 relocate_debug (bfd *output ATTRIBUTE_UNUSED,
3213 bfd *input)
3214 {
3215 #define IBS 400
3216 #define OBS 400
3217 unsigned char input_buffer[IBS];
3218
3219 input_ptr_start = input_ptr = input_buffer;
3220 input_ptr_end = input_buffer + IBS;
3221 input_bfd = input;
3222 /* FIXME: Check return value. I'm not sure whether it needs to read
3223 the entire buffer or not. */
3224 bfd_bread ((void *) input_ptr_start, (bfd_size_type) IBS, input);
3225 block ();
3226 }
3227
3228 /* Gather together all the debug information from each input BFD into
3229 one place, relocating it and emitting it as we go. */
3230
3231 static bfd_boolean
3232 ieee_write_debug_part (bfd *abfd)
3233 {
3234 ieee_data_type *ieee = IEEE_DATA (abfd);
3235 bfd_chain_type *chain = ieee->chain_root;
3236 unsigned char obuff[OBS];
3237 bfd_boolean some_debug = FALSE;
3238 file_ptr here = bfd_tell (abfd);
3239
3240 output_ptr_start = output_ptr = obuff;
3241 output_ptr_end = obuff + OBS;
3242 output_ptr = obuff;
3243 output_bfd = abfd;
3244
3245 if (chain == (bfd_chain_type *) NULL)
3246 {
3247 asection *s;
3248
3249 for (s = abfd->sections; s != NULL; s = s->next)
3250 if ((s->flags & SEC_DEBUGGING) != 0)
3251 break;
3252 if (s == NULL)
3253 {
3254 ieee->w.r.debug_information_part = 0;
3255 return TRUE;
3256 }
3257
3258 ieee->w.r.debug_information_part = here;
3259 if (bfd_bwrite (s->contents, s->size, abfd) != s->size)
3260 return FALSE;
3261 }
3262 else
3263 {
3264 while (chain != (bfd_chain_type *) NULL)
3265 {
3266 bfd *entry = chain->this;
3267 ieee_data_type *entry_ieee = IEEE_DATA (entry);
3268
3269 if (entry_ieee->w.r.debug_information_part)
3270 {
3271 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
3272 SEEK_SET) != 0)
3273 return FALSE;
3274 relocate_debug (abfd, entry);
3275 }
3276
3277 chain = chain->next;
3278 }
3279
3280 if (some_debug)
3281 ieee->w.r.debug_information_part = here;
3282 else
3283 ieee->w.r.debug_information_part = 0;
3284
3285 flush ();
3286 }
3287
3288 return TRUE;
3289 }
3290
3291 /* Write the data in an ieee way. */
3292
3293 static bfd_boolean
3294 ieee_write_data_part (bfd *abfd)
3295 {
3296 asection *s;
3297
3298 ieee_data_type *ieee = IEEE_DATA (abfd);
3299 ieee->w.r.data_part = bfd_tell (abfd);
3300
3301 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3302 {
3303 /* Skip sections that have no loadable contents (.bss,
3304 debugging, etc.) */
3305 if ((s->flags & SEC_LOAD) == 0)
3306 continue;
3307
3308 /* Sort the reloc records so we can insert them in the correct
3309 places. */
3310 if (s->reloc_count != 0)
3311 {
3312 if (! do_with_relocs (abfd, s))
3313 return FALSE;
3314 }
3315 else
3316 {
3317 if (! do_without_relocs (abfd, s))
3318 return FALSE;
3319 }
3320 }
3321
3322 return TRUE;
3323 }
3324
3325 static bfd_boolean
3326 init_for_output (bfd *abfd)
3327 {
3328 asection *s;
3329
3330 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3331 {
3332 if ((s->flags & SEC_DEBUGGING) != 0)
3333 continue;
3334 if (s->size != 0)
3335 {
3336 bfd_size_type size = s->size;
3337 ieee_per_section (s)->data = bfd_alloc (abfd, size);
3338 if (!ieee_per_section (s)->data)
3339 return FALSE;
3340 }
3341 }
3342 return TRUE;
3343 }
3344 \f
3345 /* Exec and core file sections. */
3346
3347 /* Set section contents is complicated with IEEE since the format is
3348 not a byte image, but a record stream. */
3349
3350 static bfd_boolean
3351 ieee_set_section_contents (bfd *abfd,
3352 sec_ptr section,
3353 const void * location,
3354 file_ptr offset,
3355 bfd_size_type count)
3356 {
3357 if ((section->flags & SEC_DEBUGGING) != 0)
3358 {
3359 if (section->contents == NULL)
3360 {
3361 bfd_size_type size = section->size;
3362 section->contents = bfd_alloc (abfd, size);
3363 if (section->contents == NULL)
3364 return FALSE;
3365 }
3366 /* bfd_set_section_contents has already checked that everything
3367 is within range. */
3368 memcpy (section->contents + offset, location, (size_t) count);
3369 return TRUE;
3370 }
3371
3372 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
3373 {
3374 if (!init_for_output (abfd))
3375 return FALSE;
3376 }
3377 memcpy ((void *) (ieee_per_section (section)->data + offset),
3378 (void *) location,
3379 (unsigned int) count);
3380 return TRUE;
3381 }
3382
3383 /* Write the external symbols of a file. IEEE considers two sorts of
3384 external symbols, public, and referenced. It uses to internal
3385 forms to index them as well. When we write them out we turn their
3386 symbol values into indexes from the right base. */
3387
3388 static bfd_boolean
3389 ieee_write_external_part (bfd *abfd)
3390 {
3391 asymbol **q;
3392 ieee_data_type *ieee = IEEE_DATA (abfd);
3393 unsigned int reference_index = IEEE_REFERENCE_BASE;
3394 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
3395 file_ptr here = bfd_tell (abfd);
3396 bfd_boolean hadone = FALSE;
3397
3398 if (abfd->outsymbols != (asymbol **) NULL)
3399 {
3400
3401 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
3402 {
3403 asymbol *p = *q;
3404
3405 if (bfd_is_und_section (p->section))
3406 {
3407 /* This must be a symbol reference. */
3408 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3409 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3410 || ! ieee_write_id (abfd, p->name))
3411 return FALSE;
3412 p->value = reference_index;
3413 reference_index++;
3414 hadone = TRUE;
3415 }
3416 else if (bfd_is_com_section (p->section))
3417 {
3418 /* This is a weak reference. */
3419 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
3420 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3421 || ! ieee_write_id (abfd, p->name)
3422 || ! ieee_write_byte (abfd,
3423 ieee_weak_external_reference_enum)
3424 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
3425 || ! ieee_write_int (abfd, p->value))
3426 return FALSE;
3427 p->value = reference_index;
3428 reference_index++;
3429 hadone = TRUE;
3430 }
3431 else if (p->flags & BSF_GLOBAL)
3432 {
3433 /* This must be a symbol definition. */
3434 if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
3435 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3436 || ! ieee_write_id (abfd, p->name)
3437 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
3438 || ! ieee_write_int (abfd, (bfd_vma) public_index)
3439 || ! ieee_write_byte (abfd, 15) /* Instruction address. */
3440 || ! ieee_write_byte (abfd, 19) /* Static symbol. */
3441 || ! ieee_write_byte (abfd, 1)) /* One of them. */
3442 return FALSE;
3443
3444 /* Write out the value. */
3445 if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
3446 || ! ieee_write_int (abfd, (bfd_vma) public_index))
3447 return FALSE;
3448 if (! bfd_is_abs_section (p->section))
3449 {
3450 if (abfd->flags & EXEC_P)
3451 {
3452 /* If fully linked, then output all symbols
3453 relocated. */
3454 if (! (ieee_write_int
3455 (abfd,
3456 (p->value
3457 + p->section->output_offset
3458 + p->section->output_section->vma))))
3459 return FALSE;
3460 }
3461 else
3462 {
3463 if (! (ieee_write_expression
3464 (abfd,
3465 p->value + p->section->output_offset,
3466 p->section->output_section->symbol,
3467 FALSE, 0)))
3468 return FALSE;
3469 }
3470 }
3471 else
3472 {
3473 if (! ieee_write_expression (abfd,
3474 p->value,
3475 bfd_abs_section_ptr->symbol,
3476 FALSE, 0))
3477 return FALSE;
3478 }
3479 p->value = public_index;
3480 public_index++;
3481 hadone = TRUE;
3482 }
3483 else
3484 {
3485 /* This can happen - when there are gaps in the symbols read
3486 from an input ieee file. */
3487 }
3488 }
3489 }
3490 if (hadone)
3491 ieee->w.r.external_part = here;
3492
3493 return TRUE;
3494 }
3495
3496
3497 static const unsigned char exten[] =
3498 {
3499 0xf0, 0x20, 0x00,
3500 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3501 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
3502 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
3503 };
3504
3505 static const unsigned char envi[] =
3506 {
3507 0xf0, 0x21, 0x00,
3508
3509 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3510 0x19, 0x2c,
3511 */
3512 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */
3513
3514 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */
3515 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3516 };
3517
3518 static bfd_boolean
3519 ieee_write_me_part (bfd *abfd)
3520 {
3521 ieee_data_type *ieee = IEEE_DATA (abfd);
3522 ieee->w.r.trailer_part = bfd_tell (abfd);
3523 if (abfd->start_address)
3524 {
3525 if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
3526 || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
3527 || ! ieee_write_int (abfd, abfd->start_address)
3528 || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
3529 return FALSE;
3530 }
3531 ieee->w.r.me_record = bfd_tell (abfd);
3532 if (! ieee_write_byte (abfd, ieee_module_end_enum))
3533 return FALSE;
3534 return TRUE;
3535 }
3536
3537 /* Write out the IEEE processor ID. */
3538
3539 static bfd_boolean
3540 ieee_write_processor (bfd *abfd)
3541 {
3542 const bfd_arch_info_type *arch;
3543
3544 arch = bfd_get_arch_info (abfd);
3545 switch (arch->arch)
3546 {
3547 default:
3548 if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
3549 return FALSE;
3550 break;
3551
3552 case bfd_arch_h8300:
3553 if (! ieee_write_id (abfd, "H8/300"))
3554 return FALSE;
3555 break;
3556
3557 case bfd_arch_h8500:
3558 if (! ieee_write_id (abfd, "H8/500"))
3559 return FALSE;
3560 break;
3561
3562 case bfd_arch_i960:
3563 switch (arch->mach)
3564 {
3565 default:
3566 case bfd_mach_i960_core:
3567 case bfd_mach_i960_ka_sa:
3568 if (! ieee_write_id (abfd, "80960KA"))
3569 return FALSE;
3570 break;
3571
3572 case bfd_mach_i960_kb_sb:
3573 if (! ieee_write_id (abfd, "80960KB"))
3574 return FALSE;
3575 break;
3576
3577 case bfd_mach_i960_ca:
3578 if (! ieee_write_id (abfd, "80960CA"))
3579 return FALSE;
3580 break;
3581
3582 case bfd_mach_i960_mc:
3583 case bfd_mach_i960_xa:
3584 if (! ieee_write_id (abfd, "80960MC"))
3585 return FALSE;
3586 break;
3587 }
3588 break;
3589
3590 case bfd_arch_m68k:
3591 {
3592 const char *id;
3593
3594 switch (arch->mach)
3595 {
3596 default: id = "68020"; break;
3597 case bfd_mach_m68000: id = "68000"; break;
3598 case bfd_mach_m68008: id = "68008"; break;
3599 case bfd_mach_m68010: id = "68010"; break;
3600 case bfd_mach_m68020: id = "68020"; break;
3601 case bfd_mach_m68030: id = "68030"; break;
3602 case bfd_mach_m68040: id = "68040"; break;
3603 case bfd_mach_m68060: id = "68060"; break;
3604 case bfd_mach_cpu32: id = "cpu32"; break;
3605 case bfd_mach_mcf_isa_a_nodiv: id = "isa-a:nodiv"; break;
3606 case bfd_mach_mcf_isa_a: id = "isa-a"; break;
3607 case bfd_mach_mcf_isa_a_mac: id = "isa-a:mac"; break;
3608 case bfd_mach_mcf_isa_a_emac: id = "isa-a:emac"; break;
3609 case bfd_mach_mcf_isa_aplus: id = "isa-aplus"; break;
3610 case bfd_mach_mcf_isa_aplus_mac: id = "isa-aplus:mac"; break;
3611 case bfd_mach_mcf_isa_aplus_emac: id = "isa-aplus:mac"; break;
3612 case bfd_mach_mcf_isa_b_nousp: id = "isa-b:nousp"; break;
3613 case bfd_mach_mcf_isa_b_nousp_mac: id = "isa-b:nousp:mac"; break;
3614 case bfd_mach_mcf_isa_b_nousp_emac: id = "isa-b:nousp:emac"; break;
3615 case bfd_mach_mcf_isa_b: id = "isa-b"; break;
3616 case bfd_mach_mcf_isa_b_mac: id = "isa-b:mac"; break;
3617 case bfd_mach_mcf_isa_b_emac: id = "isa-b:emac"; break;
3618 case bfd_mach_mcf_isa_b_float: id = "isa-b:float"; break;
3619 case bfd_mach_mcf_isa_b_float_mac: id = "isa-b:float:mac"; break;
3620 case bfd_mach_mcf_isa_b_float_emac: id = "isa-b:float:emac"; break;
3621 case bfd_mach_mcf_isa_c: id = "isa-c"; break;
3622 case bfd_mach_mcf_isa_c_mac: id = "isa-c:mac"; break;
3623 case bfd_mach_mcf_isa_c_emac: id = "isa-c:emac"; break;
3624 case bfd_mach_mcf_isa_c_nodiv: id = "isa-c:nodiv"; break;
3625 case bfd_mach_mcf_isa_c_nodiv_mac: id = "isa-c:nodiv:mac"; break;
3626 case bfd_mach_mcf_isa_c_nodiv_emac: id = "isa-c:nodiv:emac"; break;
3627 }
3628
3629 if (! ieee_write_id (abfd, id))
3630 return FALSE;
3631 }
3632 break;
3633 }
3634
3635 return TRUE;
3636 }
3637
3638 static bfd_boolean
3639 ieee_write_object_contents (bfd *abfd)
3640 {
3641 ieee_data_type *ieee = IEEE_DATA (abfd);
3642 unsigned int i;
3643 file_ptr old;
3644
3645 /* Fast forward over the header area. */
3646 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3647 return FALSE;
3648
3649 if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
3650 || ! ieee_write_processor (abfd)
3651 || ! ieee_write_id (abfd, abfd->filename))
3652 return FALSE;
3653
3654 /* Fast forward over the variable bits. */
3655 if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
3656 return FALSE;
3657
3658 /* Bits per MAU. */
3659 if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
3660 return FALSE;
3661 /* MAU's per address. */
3662 if (! ieee_write_byte (abfd,
3663 (bfd_byte) (bfd_arch_bits_per_address (abfd)
3664 / bfd_arch_bits_per_byte (abfd))))
3665 return FALSE;
3666
3667 old = bfd_tell (abfd);
3668 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
3669 return FALSE;
3670
3671 ieee->w.r.extension_record = bfd_tell (abfd);
3672 if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
3673 != sizeof (exten))
3674 return FALSE;
3675 if (abfd->flags & EXEC_P)
3676 {
3677 if (! ieee_write_byte (abfd, 0x1)) /* Absolute. */
3678 return FALSE;
3679 }
3680 else
3681 {
3682 if (! ieee_write_byte (abfd, 0x2)) /* Relocateable. */
3683 return FALSE;
3684 }
3685
3686 ieee->w.r.environmental_record = bfd_tell (abfd);
3687 if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
3688 != sizeof (envi))
3689 return FALSE;
3690
3691 /* The HP emulator database requires a timestamp in the file. */
3692 {
3693 time_t now;
3694 const struct tm *t;
3695
3696 time (&now);
3697 t = (struct tm *) localtime (&now);
3698 if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
3699 || ! ieee_write_byte (abfd, 0x21)
3700 || ! ieee_write_byte (abfd, 0)
3701 || ! ieee_write_byte (abfd, 50)
3702 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
3703 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
3704 || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
3705 || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
3706 || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
3707 || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
3708 return FALSE;
3709 }
3710
3711 output_bfd = abfd;
3712
3713 flush ();
3714
3715 if (! ieee_write_section_part (abfd))
3716 return FALSE;
3717 /* First write the symbols. This changes their values into table
3718 indeces so we cant use it after this point. */
3719 if (! ieee_write_external_part (abfd))
3720 return FALSE;
3721
3722 /* Write any debugs we have been told about. */
3723 if (! ieee_write_debug_part (abfd))
3724 return FALSE;
3725
3726 /* Can only write the data once the symbols have been written, since
3727 the data contains relocation information which points to the
3728 symbols. */
3729 if (! ieee_write_data_part (abfd))
3730 return FALSE;
3731
3732 /* At the end we put the end! */
3733 if (! ieee_write_me_part (abfd))
3734 return FALSE;
3735
3736 /* Generate the header. */
3737 if (bfd_seek (abfd, old, SEEK_SET) != 0)
3738 return FALSE;
3739
3740 for (i = 0; i < N_W_VARIABLES; i++)
3741 {
3742 if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
3743 || ! ieee_write_byte (abfd, (bfd_byte) i)
3744 || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
3745 return FALSE;
3746 }
3747
3748 return TRUE;
3749 }
3750 \f
3751 /* Native-level interface to symbols. */
3752
3753 /* We read the symbols into a buffer, which is discarded when this
3754 function exits. We read the strings into a buffer large enough to
3755 hold them all plus all the cached symbol entries. */
3756
3757 static asymbol *
3758 ieee_make_empty_symbol (bfd *abfd)
3759 {
3760 bfd_size_type amt = sizeof (ieee_symbol_type);
3761 ieee_symbol_type *new_symbol = (ieee_symbol_type *) bfd_zalloc (abfd, amt);
3762
3763 if (!new_symbol)
3764 return NULL;
3765 new_symbol->symbol.the_bfd = abfd;
3766 return &new_symbol->symbol;
3767 }
3768
3769 static bfd *
3770 ieee_openr_next_archived_file (bfd *arch, bfd *prev)
3771 {
3772 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
3773
3774 /* Take the next one from the arch state, or reset. */
3775 if (prev == (bfd *) NULL)
3776 /* Reset the index - the first two entries are bogus. */
3777 ar->element_index = 2;
3778
3779 while (TRUE)
3780 {
3781 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
3782
3783 ar->element_index++;
3784 if (ar->element_index <= ar->element_count)
3785 {
3786 if (p->file_offset != (file_ptr) 0)
3787 {
3788 if (p->abfd == (bfd *) NULL)
3789 {
3790 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3791 p->abfd->origin = p->file_offset;
3792 }
3793 return p->abfd;
3794 }
3795 }
3796 else
3797 {
3798 bfd_set_error (bfd_error_no_more_archived_files);
3799 return NULL;
3800 }
3801 }
3802 }
3803
3804 #define ieee_find_nearest_line _bfd_nosymbols_find_nearest_line
3805 #define ieee_find_line _bfd_nosymbols_find_line
3806 #define ieee_find_inliner_info _bfd_nosymbols_find_inliner_info
3807
3808 static int
3809 ieee_generic_stat_arch_elt (bfd *abfd, struct stat *buf)
3810 {
3811 ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
3812 ieee_data_type *ieee;
3813
3814 if (abfd->my_archive != NULL)
3815 ar = abfd->my_archive->tdata.ieee_ar_data;
3816 if (ar == (ieee_ar_data_type *) NULL)
3817 {
3818 bfd_set_error (bfd_error_invalid_operation);
3819 return -1;
3820 }
3821
3822 if (IEEE_DATA (abfd) == NULL)
3823 {
3824 if (ieee_object_p (abfd) == NULL)
3825 {
3826 bfd_set_error (bfd_error_wrong_format);
3827 return -1;
3828 }
3829 }
3830
3831 ieee = IEEE_DATA (abfd);
3832
3833 buf->st_size = ieee->w.r.me_record + 1;
3834 buf->st_mode = 0644;
3835 return 0;
3836 }
3837
3838 static int
3839 ieee_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
3840 struct bfd_link_info *info ATTRIBUTE_UNUSED)
3841 {
3842 return 0;
3843 }
3844
3845 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3846 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3847
3848 #define ieee_slurp_armap bfd_true
3849 #define ieee_slurp_extended_name_table bfd_true
3850 #define ieee_construct_extended_name_table \
3851 ((bfd_boolean (*) \
3852 (bfd *, char **, bfd_size_type *, const char **)) \
3853 bfd_true)
3854 #define ieee_truncate_arname bfd_dont_truncate_arname
3855 #define ieee_write_armap \
3856 ((bfd_boolean (*) \
3857 (bfd *, unsigned int, struct orl *, unsigned int, int)) \
3858 bfd_true)
3859 #define ieee_read_ar_hdr bfd_nullvoidptr
3860 #define ieee_write_ar_hdr ((bfd_boolean (*) (bfd *, bfd *)) bfd_false)
3861 #define ieee_update_armap_timestamp bfd_true
3862 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3863
3864 #define ieee_get_symbol_version_string \
3865 _bfd_nosymbols_get_symbol_version_string
3866 #define ieee_bfd_is_target_special_symbol \
3867 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
3868 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3869 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3870 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3871 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3872 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3873
3874 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3875 #define ieee_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
3876
3877 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3878
3879 #define ieee_get_section_contents_in_window \
3880 _bfd_generic_get_section_contents_in_window
3881 #define ieee_bfd_get_relocated_section_contents \
3882 bfd_generic_get_relocated_section_contents
3883 #define ieee_bfd_relax_section bfd_generic_relax_section
3884 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3885 #define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
3886 #define ieee_bfd_merge_sections bfd_generic_merge_sections
3887 #define ieee_bfd_is_group_section bfd_generic_is_group_section
3888 #define ieee_bfd_discard_group bfd_generic_discard_group
3889 #define ieee_section_already_linked \
3890 _bfd_generic_section_already_linked
3891 #define ieee_bfd_define_common_symbol bfd_generic_define_common_symbol
3892 #define ieee_bfd_define_start_stop bfd_generic_define_start_stop
3893 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3894 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3895 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
3896 #define ieee_bfd_copy_link_hash_symbol_type \
3897 _bfd_generic_copy_link_hash_symbol_type
3898 #define ieee_bfd_final_link _bfd_generic_final_link
3899 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3900 #define ieee_bfd_link_check_relocs _bfd_generic_link_check_relocs
3901 #define ieee_set_reloc _bfd_generic_set_reloc
3902
3903 const bfd_target ieee_vec =
3904 {
3905 "ieee", /* Name. */
3906 bfd_target_ieee_flavour,
3907 BFD_ENDIAN_UNKNOWN, /* Target byte order. */
3908 BFD_ENDIAN_UNKNOWN, /* Target headers byte order. */
3909 (HAS_RELOC | EXEC_P | /* Object flags. */
3910 HAS_LINENO | HAS_DEBUG |
3911 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3912 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3913 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
3914 '_', /* Leading underscore. */
3915 ' ', /* AR_pad_char. */
3916 16, /* AR_max_namelen. */
3917 0, /* match priority. */
3918 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3919 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3920 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
3921 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3922 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3923 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
3924
3925 {_bfd_dummy_target,
3926 ieee_object_p, /* bfd_check_format. */
3927 ieee_archive_p,
3928 _bfd_dummy_target,
3929 },
3930 {
3931 bfd_false,
3932 ieee_mkobject,
3933 _bfd_generic_mkarchive,
3934 bfd_false
3935 },
3936 {
3937 bfd_false,
3938 ieee_write_object_contents,
3939 _bfd_write_archive_contents,
3940 bfd_false,
3941 },
3942
3943 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
3944 ieee_get_section_contents, ieee_get_section_contents_in_window. */
3945 BFD_JUMP_TABLE_GENERIC (ieee),
3946
3947 BFD_JUMP_TABLE_COPY (_bfd_generic),
3948 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3949
3950 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
3951 ieee_construct_extended_name_table, ieee_truncate_arname,
3952 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
3953 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
3954 ieee_update_armap_timestamp. */
3955 BFD_JUMP_TABLE_ARCHIVE (ieee),
3956
3957 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
3958 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
3959 ieee_bfd_is_local_label_name, ieee_get_lineno,
3960 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
3961 ieee_read_minisymbols, ieee_minisymbol_to_symbol. */
3962 BFD_JUMP_TABLE_SYMBOLS (ieee),
3963
3964 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
3965 ieee_bfd_reloc_type_lookup. */
3966 BFD_JUMP_TABLE_RELOCS (ieee),
3967
3968 /* ieee_set_arch_mach, ieee_set_section_contents. */
3969 BFD_JUMP_TABLE_WRITE (ieee),
3970
3971 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
3972 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
3973 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
3974 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
3975 ieee_bfd_merge_sections. */
3976 BFD_JUMP_TABLE_LINK (ieee),
3977
3978 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
3979
3980 NULL,
3981
3982 NULL
3983 };
This page took 0.113539 seconds and 4 git commands to generate.