OSDN Git Service

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