Back to index

cell-binutils  2.17cvs20070401
ieee.c
Go to the documentation of this file.
00001 /* BFD back-end for ieee-695 objects.
00002    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
00003    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
00004    Free Software Foundation, Inc.
00005 
00006    Written by Steve Chamberlain of Cygnus Support.
00007 
00008    This file is part of BFD, the Binary File Descriptor library.
00009 
00010    This program is free software; you can redistribute it and/or modify
00011    it under the terms of the GNU General Public License as published by
00012    the Free Software Foundation; either version 2 of the License, or
00013    (at your option) any later version.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License
00021    along with this program; if not, write to the Free Software
00022    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00023 
00024 #define KEEPMINUSPCININST 0
00025 
00026 /* IEEE 695 format is a stream of records, which we parse using a simple one-
00027    token (which is one byte in this lexicon) lookahead recursive decent
00028    parser.  */
00029 
00030 #include "bfd.h"
00031 #include "sysdep.h"
00032 #include "libbfd.h"
00033 #include "ieee.h"
00034 #include "libieee.h"
00035 #include "safe-ctype.h"
00036 
00037 struct output_buffer_struct
00038 {
00039   unsigned char *ptrp;
00040   int buffer;
00041 };
00042 
00043 static unsigned char *output_ptr_start;
00044 static unsigned char *output_ptr;
00045 static unsigned char *output_ptr_end;
00046 static unsigned char *input_ptr_start;
00047 static unsigned char *input_ptr;
00048 static unsigned char *input_ptr_end;
00049 static bfd *input_bfd;
00050 static bfd *output_bfd;
00051 static int output_buffer;
00052 
00053 
00054 static void block (void);
00055 
00056 /* Functions for writing to ieee files in the strange way that the
00057    standard requires.  */
00058 
00059 static bfd_boolean
00060 ieee_write_byte (bfd *abfd, int barg)
00061 {
00062   bfd_byte byte;
00063 
00064   byte = barg;
00065   if (bfd_bwrite ((void *) &byte, (bfd_size_type) 1, abfd) != 1)
00066     return FALSE;
00067   return TRUE;
00068 }
00069 
00070 static bfd_boolean
00071 ieee_write_2bytes (bfd *abfd, int bytes)
00072 {
00073   bfd_byte buffer[2];
00074 
00075   buffer[0] = bytes >> 8;
00076   buffer[1] = bytes & 0xff;
00077   if (bfd_bwrite ((void *) buffer, (bfd_size_type) 2, abfd) != 2)
00078     return FALSE;
00079   return TRUE;
00080 }
00081 
00082 static bfd_boolean
00083 ieee_write_int (bfd *abfd, bfd_vma value)
00084 {
00085   if (value <= 127)
00086     {
00087       if (! ieee_write_byte (abfd, (bfd_byte) value))
00088        return FALSE;
00089     }
00090   else
00091     {
00092       unsigned int length;
00093 
00094       /* How many significant bytes ?  */
00095       /* FIXME FOR LONGER INTS.  */
00096       if (value & 0xff000000)
00097        length = 4;
00098       else if (value & 0x00ff0000)
00099        length = 3;
00100       else if (value & 0x0000ff00)
00101        length = 2;
00102       else
00103        length = 1;
00104 
00105       if (! ieee_write_byte (abfd,
00106                           (bfd_byte) ((int) ieee_number_repeat_start_enum
00107                                     + length)))
00108        return FALSE;
00109       switch (length)
00110        {
00111        case 4:
00112          if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))
00113            return FALSE;
00114          /* Fall through.  */
00115        case 3:
00116          if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))
00117            return FALSE;
00118          /* Fall through.  */
00119        case 2:
00120          if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))
00121            return FALSE;
00122          /* Fall through.  */
00123        case 1:
00124          if (! ieee_write_byte (abfd, (bfd_byte) (value)))
00125            return FALSE;
00126        }
00127     }
00128 
00129   return TRUE;
00130 }
00131 
00132 static bfd_boolean
00133 ieee_write_id (bfd *abfd, const char *id)
00134 {
00135   size_t length = strlen (id);
00136 
00137   if (length <= 127)
00138     {
00139       if (! ieee_write_byte (abfd, (bfd_byte) length))
00140        return FALSE;
00141     }
00142   else if (length < 255)
00143     {
00144       if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)
00145          || ! ieee_write_byte (abfd, (bfd_byte) length))
00146        return FALSE;
00147     }
00148   else if (length < 65535)
00149     {
00150       if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)
00151          || ! ieee_write_2bytes (abfd, (int) length))
00152        return FALSE;
00153     }
00154   else
00155     {
00156       (*_bfd_error_handler)
00157        (_("%s: string too long (%d chars, max 65535)"),
00158         bfd_get_filename (abfd), length);
00159       bfd_set_error (bfd_error_invalid_operation);
00160       return FALSE;
00161     }
00162 
00163   if (bfd_bwrite ((void *) id, (bfd_size_type) length, abfd) != length)
00164     return FALSE;
00165   return TRUE;
00166 }
00167 
00168 /* Functions for reading from ieee files in the strange way that the
00169    standard requires.  */
00170 
00171 #define this_byte(ieee)           *((ieee)->input_p)
00172 #define next_byte(ieee)            ((ieee)->input_p++)
00173 #define this_byte_and_next(ieee) (*((ieee)->input_p++))
00174 
00175 static unsigned short
00176 read_2bytes (common_header_type *ieee)
00177 {
00178   unsigned char c1 = this_byte_and_next (ieee);
00179   unsigned char c2 = this_byte_and_next (ieee);
00180 
00181   return (c1 << 8) | c2;
00182 }
00183 
00184 static void
00185 bfd_get_string (common_header_type *ieee, char *string, size_t length)
00186 {
00187   size_t i;
00188 
00189   for (i = 0; i < length; i++)
00190     string[i] = this_byte_and_next (ieee);
00191 }
00192 
00193 static char *
00194 read_id (common_header_type *ieee)
00195 {
00196   size_t length;
00197   char *string;
00198 
00199   length = this_byte_and_next (ieee);
00200   if (length <= 0x7f)
00201     /* Simple string of length 0 to 127.  */
00202     ;
00203 
00204   else if (length == 0xde)
00205     /* Length is next byte, allowing 0..255.  */
00206     length = this_byte_and_next (ieee);
00207 
00208   else if (length == 0xdf)
00209     {
00210       /* Length is next two bytes, allowing 0..65535.  */
00211       length = this_byte_and_next (ieee);
00212       length = (length * 256) + this_byte_and_next (ieee);
00213     }
00214 
00215   /* Buy memory and read string.  */
00216   string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
00217   if (!string)
00218     return NULL;
00219   bfd_get_string (ieee, string, length);
00220   string[length] = 0;
00221   return string;
00222 }
00223 
00224 static bfd_boolean
00225 ieee_write_expression (bfd *abfd,
00226                      bfd_vma value,
00227                      asymbol *symbol,
00228                      bfd_boolean pcrel,
00229                      unsigned int index)
00230 {
00231   unsigned int term_count = 0;
00232 
00233   if (value != 0)
00234     {
00235       if (! ieee_write_int (abfd, value))
00236        return FALSE;
00237       term_count++;
00238     }
00239 
00240   /* Badly formatted binaries can have a missing symbol,
00241      so test here to prevent a seg fault.  */
00242   if (symbol != NULL)
00243     {
00244       if (bfd_is_com_section (symbol->section)
00245          || bfd_is_und_section (symbol->section))
00246        {
00247          /* Def of a common symbol.  */
00248          if (! ieee_write_byte (abfd, ieee_variable_X_enum)
00249              || ! ieee_write_int (abfd, symbol->value))
00250            return FALSE;
00251          term_count ++;
00252        }
00253       else if (! bfd_is_abs_section (symbol->section))
00254        {
00255          /* Ref to defined symbol -  */
00256          if (symbol->flags & BSF_GLOBAL)
00257            {
00258              if (! ieee_write_byte (abfd, ieee_variable_I_enum)
00259                 || ! ieee_write_int (abfd, symbol->value))
00260               return FALSE;
00261              term_count++;
00262            }
00263          else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
00264            {
00265              /* This is a reference to a defined local symbol.  We can
00266                easily do a local as a section+offset.  */
00267              if (! ieee_write_byte (abfd, ieee_variable_R_enum)
00268                 || ! ieee_write_byte (abfd,
00269                                    (bfd_byte) (symbol->section->index
00270                                               + IEEE_SECTION_NUMBER_BASE)))
00271               return FALSE;
00272 
00273              term_count++;
00274              if (symbol->value != 0)
00275               {
00276                 if (! ieee_write_int (abfd, symbol->value))
00277                   return FALSE;
00278                 term_count++;
00279               }
00280            }
00281          else
00282            {
00283              (*_bfd_error_handler)
00284               (_("%s: unrecognized symbol `%s' flags 0x%x"),
00285                bfd_get_filename (abfd), bfd_asymbol_name (symbol),
00286                symbol->flags);
00287              bfd_set_error (bfd_error_invalid_operation);
00288              return FALSE;
00289            }
00290        }
00291     }
00292 
00293   if (pcrel)
00294     {
00295       /* Subtract the pc from here by asking for PC of this section.  */
00296       if (! ieee_write_byte (abfd, ieee_variable_P_enum)
00297          || ! ieee_write_byte (abfd,
00298                             (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE))
00299          || ! ieee_write_byte (abfd, ieee_function_minus_enum))
00300        return FALSE;
00301     }
00302 
00303   /* Handle the degenerate case of a 0 address.  */
00304   if (term_count == 0)
00305     if (! ieee_write_int (abfd, (bfd_vma) 0))
00306       return FALSE;
00307 
00308   while (term_count > 1)
00309     {
00310       if (! ieee_write_byte (abfd, ieee_function_plus_enum))
00311        return FALSE;
00312       term_count--;
00313     }
00314 
00315   return TRUE;
00316 }
00317 
00318 /* Writes any integer into the buffer supplied and always takes 5 bytes.  */
00319 
00320 static void
00321 ieee_write_int5 (bfd_byte *buffer, bfd_vma value)
00322 {
00323   buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
00324   buffer[1] = (value >> 24) & 0xff;
00325   buffer[2] = (value >> 16) & 0xff;
00326   buffer[3] = (value >> 8) & 0xff;
00327   buffer[4] = (value >> 0) & 0xff;
00328 }
00329 
00330 static bfd_boolean
00331 ieee_write_int5_out (bfd *abfd, bfd_vma value)
00332 {
00333   bfd_byte b[5];
00334 
00335   ieee_write_int5 (b, value);
00336   if (bfd_bwrite ((void *) b, (bfd_size_type) 5, abfd) != 5)
00337     return FALSE;
00338   return TRUE;
00339 }
00340 
00341 static bfd_boolean
00342 parse_int (common_header_type *ieee, bfd_vma *value_ptr)
00343 {
00344   int value = this_byte (ieee);
00345   int result;
00346 
00347   if (value >= 0 && value <= 127)
00348     {
00349       *value_ptr = value;
00350       next_byte (ieee);
00351       return TRUE;
00352     }
00353   else if (value >= 0x80 && value <= 0x88)
00354     {
00355       unsigned int count = value & 0xf;
00356 
00357       result = 0;
00358       next_byte (ieee);
00359       while (count)
00360        {
00361          result = (result << 8) | this_byte_and_next (ieee);
00362          count--;
00363        }
00364       *value_ptr = result;
00365       return TRUE;
00366     }
00367   return FALSE;
00368 }
00369 
00370 static int
00371 parse_i (common_header_type *ieee, bfd_boolean *ok)
00372 {
00373   bfd_vma x;
00374   *ok = parse_int (ieee, &x);
00375   return x;
00376 }
00377 
00378 static bfd_vma
00379 must_parse_int (common_header_type *ieee)
00380 {
00381   bfd_vma result;
00382   BFD_ASSERT (parse_int (ieee, &result));
00383   return result;
00384 }
00385 
00386 typedef struct
00387 {
00388   bfd_vma value;
00389   asection *section;
00390   ieee_symbol_index_type symbol;
00391 } ieee_value_type;
00392 
00393 
00394 #if KEEPMINUSPCININST
00395 
00396 #define SRC_MASK(arg) arg
00397 #define PCREL_OFFSET FALSE
00398 
00399 #else
00400 
00401 #define SRC_MASK(arg) 0
00402 #define PCREL_OFFSET TRUE
00403 
00404 #endif
00405 
00406 static reloc_howto_type abs32_howto =
00407   HOWTO (1,
00408         0,
00409         2,
00410         32,
00411         FALSE,
00412         0,
00413         complain_overflow_bitfield,
00414         0,
00415         "abs32",
00416         TRUE,
00417         0xffffffff,
00418         0xffffffff,
00419         FALSE);
00420 
00421 static reloc_howto_type abs16_howto =
00422   HOWTO (1,
00423         0,
00424         1,
00425         16,
00426         FALSE,
00427         0,
00428         complain_overflow_bitfield,
00429         0,
00430         "abs16",
00431         TRUE,
00432         0x0000ffff,
00433         0x0000ffff,
00434         FALSE);
00435 
00436 static reloc_howto_type abs8_howto =
00437   HOWTO (1,
00438         0,
00439         0,
00440         8,
00441         FALSE,
00442         0,
00443         complain_overflow_bitfield,
00444         0,
00445         "abs8",
00446         TRUE,
00447         0x000000ff,
00448         0x000000ff,
00449         FALSE);
00450 
00451 static reloc_howto_type rel32_howto =
00452   HOWTO (1,
00453         0,
00454         2,
00455         32,
00456         TRUE,
00457         0,
00458         complain_overflow_signed,
00459         0,
00460         "rel32",
00461         TRUE,
00462         SRC_MASK (0xffffffff),
00463         0xffffffff,
00464         PCREL_OFFSET);
00465 
00466 static reloc_howto_type rel16_howto =
00467   HOWTO (1,
00468         0,
00469         1,
00470         16,
00471         TRUE,
00472         0,
00473         complain_overflow_signed,
00474         0,
00475         "rel16",
00476         TRUE,
00477         SRC_MASK (0x0000ffff),
00478         0x0000ffff,
00479         PCREL_OFFSET);
00480 
00481 static reloc_howto_type rel8_howto =
00482   HOWTO (1,
00483         0,
00484         0,
00485         8,
00486         TRUE,
00487         0,
00488         complain_overflow_signed,
00489         0,
00490         "rel8",
00491         TRUE,
00492         SRC_MASK (0x000000ff),
00493         0x000000ff,
00494         PCREL_OFFSET);
00495 
00496 static ieee_symbol_index_type NOSYMBOL = {0, 0};
00497 
00498 static void
00499 parse_expression (ieee_data_type *ieee,
00500                 bfd_vma *value,
00501                 ieee_symbol_index_type *symbol,
00502                 bfd_boolean *pcrel,
00503                 unsigned int *extra,
00504                 asection **section)
00505 
00506 {
00507   bfd_boolean loop = TRUE;
00508   ieee_value_type stack[10];
00509   ieee_value_type *sp = stack;
00510   asection *dummy;
00511 
00512 #define POS sp[1]
00513 #define TOS sp[0]
00514 #define NOS sp[-1]
00515 #define INC sp++;
00516 #define DEC sp--;
00517 
00518   /* The stack pointer always points to the next unused location.  */
00519 #define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC;
00520 #define POP(x,y,z)  DEC; x = TOS.symbol; y = TOS.section; z = TOS.value;
00521 
00522   while (loop && ieee->h.input_p < ieee->h.last_byte)
00523     {
00524       switch (this_byte (&(ieee->h)))
00525        {
00526        case ieee_variable_P_enum:
00527          /* P variable, current program counter for section n.  */
00528          {
00529            int section_n;
00530 
00531            next_byte (&(ieee->h));
00532            *pcrel = TRUE;
00533            section_n = must_parse_int (&(ieee->h));
00534            PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
00535            break;
00536          }
00537        case ieee_variable_L_enum:
00538          /* L variable  address of section N.  */
00539          next_byte (&(ieee->h));
00540          PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
00541          break;
00542        case ieee_variable_R_enum:
00543          /* R variable, logical address of section module.  */
00544          /* FIXME, this should be different to L.  */
00545          next_byte (&(ieee->h));
00546          PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
00547          break;
00548        case ieee_variable_S_enum:
00549          /* S variable, size in MAUS of section module.  */
00550          next_byte (&(ieee->h));
00551          PUSH (NOSYMBOL,
00552               0,
00553               ieee->section_table[must_parse_int (&(ieee->h))]->size);
00554          break;
00555        case ieee_variable_I_enum:
00556          /* Push the address of variable n.  */
00557          {
00558            ieee_symbol_index_type sy;
00559 
00560            next_byte (&(ieee->h));
00561            sy.index = (int) must_parse_int (&(ieee->h));
00562            sy.letter = 'I';
00563 
00564            PUSH (sy, bfd_abs_section_ptr, 0);
00565          }
00566          break;
00567        case ieee_variable_X_enum:
00568          /* Push the address of external variable n.  */
00569          {
00570            ieee_symbol_index_type sy;
00571 
00572            next_byte (&(ieee->h));
00573            sy.index = (int) (must_parse_int (&(ieee->h)));
00574            sy.letter = 'X';
00575 
00576            PUSH (sy, bfd_und_section_ptr, 0);
00577          }
00578          break;
00579        case ieee_function_minus_enum:
00580          {
00581            bfd_vma value1, value2;
00582            asection *section1, *section_dummy;
00583            ieee_symbol_index_type sy;
00584 
00585            next_byte (&(ieee->h));
00586 
00587            POP (sy, section1, value1);
00588            POP (sy, section_dummy, value2);
00589            PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
00590          }
00591          break;
00592        case ieee_function_plus_enum:
00593          {
00594            bfd_vma value1, value2;
00595            asection *section1;
00596            asection *section2;
00597            ieee_symbol_index_type sy1;
00598            ieee_symbol_index_type sy2;
00599 
00600            next_byte (&(ieee->h));
00601 
00602            POP (sy1, section1, value1);
00603            POP (sy2, section2, value2);
00604            PUSH (sy1.letter ? sy1 : sy2,
00605                 bfd_is_abs_section (section1) ? section2 : section1,
00606                 value1 + value2);
00607          }
00608          break;
00609        default:
00610          {
00611            bfd_vma va;
00612 
00613            BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
00614                   || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
00615            if (parse_int (&(ieee->h), &va))
00616              {
00617               PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
00618              }
00619            else
00620              /* Thats all that we can understand.  */
00621              loop = FALSE;
00622          }
00623        }
00624     }
00625 
00626   /* As far as I can see there is a bug in the Microtec IEEE output
00627      which I'm using to scan, whereby the comma operator is omitted
00628      sometimes in an expression, giving expressions with too many
00629      terms.  We can tell if that's the case by ensuring that
00630      sp == stack here.  If not, then we've pushed something too far,
00631      so we keep adding.  */
00632   while (sp != stack + 1)
00633     {
00634       asection *section1;
00635       ieee_symbol_index_type sy1;
00636 
00637       POP (sy1, section1, *extra);
00638     }
00639 
00640   POP (*symbol, dummy, *value);
00641   if (section)
00642     *section = dummy;
00643 }
00644 
00645 
00646 #define ieee_seek(ieee, offset) \
00647   do                                                    \
00648     {                                                   \
00649       ieee->h.input_p = ieee->h.first_byte + offset;           \
00650       ieee->h.last_byte = (ieee->h.first_byte                  \
00651                         + ieee_part_after (ieee, offset));     \
00652     }                                                   \
00653   while (0)
00654 
00655 #define ieee_pos(ieee) \
00656   (ieee->h.input_p - ieee->h.first_byte)
00657 
00658 /* Find the first part of the ieee file after HERE.  */
00659 
00660 static file_ptr
00661 ieee_part_after (ieee_data_type *ieee, file_ptr here)
00662 {
00663   int part;
00664   file_ptr after = ieee->w.r.me_record;
00665 
00666   /* File parts can come in any order, except that module end is
00667      guaranteed to be last (and the header first).  */
00668   for (part = 0; part < N_W_VARIABLES; part++)
00669     if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
00670       after = ieee->w.offset[part];
00671 
00672   return after;
00673 }
00674 
00675 static unsigned int last_index;
00676 static char last_type;             /* Is the index for an X or a D.  */
00677 
00678 static ieee_symbol_type *
00679 get_symbol (bfd *abfd ATTRIBUTE_UNUSED,
00680            ieee_data_type *ieee,
00681            ieee_symbol_type *last_symbol,
00682            unsigned int *symbol_count,
00683            ieee_symbol_type ***pptr,
00684            unsigned int *max_index,
00685            int this_type)
00686 {
00687   /* Need a new symbol.  */
00688   unsigned int new_index = must_parse_int (&(ieee->h));
00689 
00690   if (new_index != last_index || this_type != last_type)
00691     {
00692       ieee_symbol_type *new_symbol;
00693       bfd_size_type amt = sizeof (ieee_symbol_type);
00694 
00695       new_symbol = bfd_alloc (ieee->h.abfd, amt);
00696       if (!new_symbol)
00697        return NULL;
00698 
00699       new_symbol->index = new_index;
00700       last_index = new_index;
00701       (*symbol_count)++;
00702       **pptr = new_symbol;
00703       *pptr = &new_symbol->next;
00704       if (new_index > *max_index)
00705        *max_index = new_index;
00706 
00707       last_type = this_type;
00708       new_symbol->symbol.section = bfd_abs_section_ptr;
00709       return new_symbol;
00710     }
00711   return last_symbol;
00712 }
00713 
00714 static bfd_boolean
00715 ieee_slurp_external_symbols (bfd *abfd)
00716 {
00717   ieee_data_type *ieee = IEEE_DATA (abfd);
00718   file_ptr offset = ieee->w.r.external_part;
00719 
00720   ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
00721   ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
00722   ieee_symbol_type *symbol = NULL;
00723   unsigned int symbol_count = 0;
00724   bfd_boolean loop = TRUE;
00725 
00726   last_index = 0xffffff;
00727   ieee->symbol_table_full = TRUE;
00728 
00729   ieee_seek (ieee, offset);
00730 
00731   while (loop)
00732     {
00733       switch (this_byte (&(ieee->h)))
00734        {
00735        case ieee_nn_record:
00736          next_byte (&(ieee->h));
00737 
00738          symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
00739                             & prev_symbols_ptr,
00740                             & ieee->external_symbol_max_index, 'I');
00741          if (symbol == NULL)
00742            return FALSE;
00743 
00744          symbol->symbol.the_bfd = abfd;
00745          symbol->symbol.name = read_id (&(ieee->h));
00746          symbol->symbol.udata.p = NULL;
00747          symbol->symbol.flags = BSF_NO_FLAGS;
00748          break;
00749        case ieee_external_symbol_enum:
00750          next_byte (&(ieee->h));
00751 
00752          symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
00753                             &prev_symbols_ptr,
00754                             &ieee->external_symbol_max_index, 'D');
00755          if (symbol == NULL)
00756            return FALSE;
00757 
00758          BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
00759 
00760          symbol->symbol.the_bfd = abfd;
00761          symbol->symbol.name = read_id (&(ieee->h));
00762          symbol->symbol.udata.p = NULL;
00763          symbol->symbol.flags = BSF_NO_FLAGS;
00764          break;
00765        case ieee_attribute_record_enum >> 8:
00766          {
00767            unsigned int symbol_name_index;
00768            unsigned int symbol_type_index;
00769            unsigned int symbol_attribute_def;
00770            bfd_vma value;
00771 
00772            switch (read_2bytes (&ieee->h))
00773              {
00774              case ieee_attribute_record_enum:
00775               symbol_name_index = must_parse_int (&(ieee->h));
00776               symbol_type_index = must_parse_int (&(ieee->h));
00777               symbol_attribute_def = must_parse_int (&(ieee->h));
00778               switch (symbol_attribute_def)
00779                 {
00780                 case 8:
00781                 case 19:
00782                   parse_int (&ieee->h, &value);
00783                   break;
00784                 default:
00785                   (*_bfd_error_handler)
00786                     (_("%B: unimplemented ATI record %u for symbol %u"),
00787                      abfd, symbol_attribute_def, symbol_name_index);
00788                   bfd_set_error (bfd_error_bad_value);
00789                   return FALSE;
00790                   break;
00791                 }
00792               break;
00793              case ieee_external_reference_info_record_enum:
00794               /* Skip over ATX record.  */
00795               parse_int (&(ieee->h), &value);
00796               parse_int (&(ieee->h), &value);
00797               parse_int (&(ieee->h), &value);
00798               parse_int (&(ieee->h), &value);
00799               break;
00800              case ieee_atn_record_enum:
00801               /* We may get call optimization information here,
00802                  which we just ignore.  The format is
00803                  {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}.  */
00804               parse_int (&ieee->h, &value);
00805               parse_int (&ieee->h, &value);
00806               parse_int (&ieee->h, &value);
00807               if (value != 0x3f)
00808                 {
00809                   (*_bfd_error_handler)
00810                     (_("%B: unexpected ATN type %d in external part"),
00811                       abfd, (int) value);
00812                   bfd_set_error (bfd_error_bad_value);
00813                   return FALSE;
00814                 }
00815               parse_int (&ieee->h, &value);
00816               parse_int (&ieee->h, &value);
00817               while (value > 0)
00818                 {
00819                   bfd_vma val1;
00820 
00821                   --value;
00822 
00823                   switch (read_2bytes (&ieee->h))
00824                     {
00825                     case ieee_asn_record_enum:
00826                      parse_int (&ieee->h, &val1);
00827                      parse_int (&ieee->h, &val1);
00828                      break;
00829 
00830                     default:
00831                      (*_bfd_error_handler)
00832                        (_("%B: unexpected type after ATN"), abfd);
00833                      bfd_set_error (bfd_error_bad_value);
00834                      return FALSE;
00835                     }
00836                 }
00837              }
00838          }
00839          break;
00840        case ieee_value_record_enum >> 8:
00841          {
00842            unsigned int symbol_name_index;
00843            ieee_symbol_index_type symbol_ignore;
00844            bfd_boolean pcrel_ignore;
00845            unsigned int extra;
00846 
00847            next_byte (&(ieee->h));
00848            next_byte (&(ieee->h));
00849 
00850            symbol_name_index = must_parse_int (&(ieee->h));
00851            parse_expression (ieee,
00852                            &symbol->symbol.value,
00853                            &symbol_ignore,
00854                            &pcrel_ignore,
00855                            &extra,
00856                            &symbol->symbol.section);
00857 
00858            /* Fully linked IEEE-695 files tend to give every symbol
00859                an absolute value.  Try to convert that back into a
00860                section relative value.  FIXME: This won't always to
00861                the right thing.  */
00862            if (bfd_is_abs_section (symbol->symbol.section)
00863               && (abfd->flags & HAS_RELOC) == 0)
00864              {
00865               bfd_vma val;
00866               asection *s;
00867 
00868               val = symbol->symbol.value;
00869               for (s = abfd->sections; s != NULL; s = s->next)
00870                 {
00871                   if (val >= s->vma && val < s->vma + s->size)
00872                     {
00873                      symbol->symbol.section = s;
00874                      symbol->symbol.value -= s->vma;
00875                      break;
00876                     }
00877                 }
00878              }
00879 
00880            symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
00881 
00882          }
00883          break;
00884        case ieee_weak_external_reference_enum:
00885          {
00886            bfd_vma size;
00887            bfd_vma value;
00888 
00889            next_byte (&(ieee->h));
00890            /* Throw away the external reference index.  */
00891            (void) must_parse_int (&(ieee->h));
00892            /* Fetch the default size if not resolved.  */
00893            size = must_parse_int (&(ieee->h));
00894            /* Fetch the default value if available.  */
00895            if (! parse_int (&(ieee->h), &value))
00896              value = 0;
00897            /* This turns into a common.  */
00898            symbol->symbol.section = bfd_com_section_ptr;
00899            symbol->symbol.value = size;
00900          }
00901          break;
00902 
00903        case ieee_external_reference_enum:
00904          next_byte (&(ieee->h));
00905 
00906          symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
00907                             &prev_reference_ptr,
00908                             &ieee->external_reference_max_index, 'X');
00909          if (symbol == NULL)
00910            return FALSE;
00911 
00912          symbol->symbol.the_bfd = abfd;
00913          symbol->symbol.name = read_id (&(ieee->h));
00914          symbol->symbol.udata.p = NULL;
00915          symbol->symbol.section = bfd_und_section_ptr;
00916          symbol->symbol.value = (bfd_vma) 0;
00917          symbol->symbol.flags = 0;
00918 
00919          BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
00920          break;
00921 
00922        default:
00923          loop = FALSE;
00924        }
00925     }
00926 
00927   if (ieee->external_symbol_max_index != 0)
00928     {
00929       ieee->external_symbol_count =
00930        ieee->external_symbol_max_index -
00931        ieee->external_symbol_min_index + 1;
00932     }
00933   else
00934     ieee->external_symbol_count = 0;
00935 
00936   if (ieee->external_reference_max_index != 0)
00937     {
00938       ieee->external_reference_count =
00939        ieee->external_reference_max_index -
00940        ieee->external_reference_min_index + 1;
00941     }
00942   else
00943     ieee->external_reference_count = 0;
00944 
00945   abfd->symcount =
00946     ieee->external_reference_count + ieee->external_symbol_count;
00947 
00948   if (symbol_count != abfd->symcount)
00949     /* There are gaps in the table -- */
00950     ieee->symbol_table_full = FALSE;
00951 
00952   *prev_symbols_ptr   = NULL;
00953   *prev_reference_ptr = NULL;
00954 
00955   return TRUE;
00956 }
00957 
00958 static bfd_boolean
00959 ieee_slurp_symbol_table (bfd *abfd)
00960 {
00961   if (! IEEE_DATA (abfd)->read_symbols)
00962     {
00963       if (! ieee_slurp_external_symbols (abfd))
00964        return FALSE;
00965       IEEE_DATA (abfd)->read_symbols = TRUE;
00966     }
00967   return TRUE;
00968 }
00969 
00970 static long
00971 ieee_get_symtab_upper_bound (bfd *abfd)
00972 {
00973   if (! ieee_slurp_symbol_table (abfd))
00974     return -1;
00975 
00976   return (abfd->symcount != 0) ?
00977     (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
00978 }
00979 
00980 /* Move from our internal lists to the canon table, and insert in
00981    symbol index order.  */
00982 
00983 extern const bfd_target ieee_vec;
00984 
00985 static long
00986 ieee_canonicalize_symtab (bfd *abfd, asymbol **location)
00987 {
00988   ieee_symbol_type *symp;
00989   static bfd dummy_bfd;
00990   static asymbol empty_symbol =
00991   {
00992     &dummy_bfd,
00993     " ieee empty",
00994     (symvalue) 0,
00995     BSF_DEBUGGING,
00996     bfd_abs_section_ptr
00997 #ifdef __STDC__
00998     /* K&R compilers can't initialise unions.  */
00999     , { 0 }
01000 #endif
01001   };
01002 
01003   if (abfd->symcount)
01004     {
01005       ieee_data_type *ieee = IEEE_DATA (abfd);
01006 
01007       dummy_bfd.xvec = &ieee_vec;
01008       if (! ieee_slurp_symbol_table (abfd))
01009        return -1;
01010 
01011       if (! ieee->symbol_table_full)
01012        {
01013          /* Arrgh - there are gaps in the table, run through and fill them
01014             up with pointers to a null place.  */
01015          unsigned int i;
01016 
01017          for (i = 0; i < abfd->symcount; i++)
01018            location[i] = &empty_symbol;
01019        }
01020 
01021       ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
01022       for (symp = IEEE_DATA (abfd)->external_symbols;
01023           symp != (ieee_symbol_type *) NULL;
01024           symp = symp->next)
01025        /* Place into table at correct index locations.  */
01026        location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
01027 
01028       /* The external refs are indexed in a bit.  */
01029       ieee->external_reference_base_offset =
01030        -ieee->external_reference_min_index + ieee->external_symbol_count;
01031 
01032       for (symp = IEEE_DATA (abfd)->external_reference;
01033           symp != (ieee_symbol_type *) NULL;
01034           symp = symp->next)
01035        location[symp->index + ieee->external_reference_base_offset] =
01036          &symp->symbol;
01037     }
01038 
01039   if (abfd->symcount)
01040     location[abfd->symcount] = (asymbol *) NULL;
01041 
01042   return abfd->symcount;
01043 }
01044 
01045 static asection *
01046 get_section_entry (bfd *abfd, ieee_data_type *ieee, unsigned int index)
01047 {
01048   if (index >= ieee->section_table_size)
01049     {
01050       unsigned int c, i;
01051       asection **n;
01052       bfd_size_type amt;
01053 
01054       c = ieee->section_table_size;
01055       if (c == 0)
01056        c = 20;
01057       while (c <= index)
01058        c *= 2;
01059 
01060       amt = c;
01061       amt *= sizeof (asection *);
01062       n = bfd_realloc (ieee->section_table, amt);
01063       if (n == NULL)
01064        return NULL;
01065 
01066       for (i = ieee->section_table_size; i < c; i++)
01067        n[i] = NULL;
01068 
01069       ieee->section_table = n;
01070       ieee->section_table_size = c;
01071     }
01072 
01073   if (ieee->section_table[index] == (asection *) NULL)
01074     {
01075       char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
01076       asection *section;
01077 
01078       if (!tmp)
01079        return NULL;
01080       sprintf (tmp, " fsec%4d", index);
01081       section = bfd_make_section (abfd, tmp);
01082       ieee->section_table[index] = section;
01083       section->target_index = index;
01084       ieee->section_table[index] = section;
01085     }
01086   return ieee->section_table[index];
01087 }
01088 
01089 static void
01090 ieee_slurp_sections (bfd *abfd)
01091 {
01092   ieee_data_type *ieee = IEEE_DATA (abfd);
01093   file_ptr offset = ieee->w.r.section_part;
01094   char *name;
01095 
01096   if (offset != 0)
01097     {
01098       bfd_byte section_type[3];
01099 
01100       ieee_seek (ieee, offset);
01101       while (TRUE)
01102        {
01103          switch (this_byte (&(ieee->h)))
01104            {
01105            case ieee_section_type_enum:
01106              {
01107               asection *section;
01108               unsigned int section_index;
01109 
01110               next_byte (&(ieee->h));
01111               section_index = must_parse_int (&(ieee->h));
01112 
01113               section = get_section_entry (abfd, ieee, section_index);
01114 
01115               section_type[0] = this_byte_and_next (&(ieee->h));
01116 
01117               /* Set minimal section attributes. Attributes are
01118                  extended later, based on section contents.  */
01119               switch (section_type[0])
01120                 {
01121                 case 0xC1:
01122                   /* Normal attributes for absolute sections.  */
01123                   section_type[1] = this_byte (&(ieee->h));
01124                   section->flags = SEC_ALLOC;
01125                   switch (section_type[1])
01126                     {
01127                      /* AS Absolute section attributes.  */
01128                     case 0xD3:
01129                      next_byte (&(ieee->h));
01130                      section_type[2] = this_byte (&(ieee->h));
01131                      switch (section_type[2])
01132                        {
01133                        case 0xD0:
01134                          /* Normal code.  */
01135                          next_byte (&(ieee->h));
01136                          section->flags |= SEC_CODE;
01137                          break;
01138                        case 0xC4:
01139                          /* Normal data.  */
01140                          next_byte (&(ieee->h));
01141                          section->flags |= SEC_DATA;
01142                          break;
01143                        case 0xD2:
01144                          next_byte (&(ieee->h));
01145                          /* Normal rom data.  */
01146                          section->flags |= SEC_ROM | SEC_DATA;
01147                          break;
01148                        default:
01149                          break;
01150                        }
01151                     }
01152                   break;
01153 
01154                   /* Named relocatable sections (type C).  */
01155                 case 0xC3:
01156                   section_type[1] = this_byte (&(ieee->h));
01157                   section->flags = SEC_ALLOC;
01158                   switch (section_type[1])
01159                     {
01160                     case 0xD0:     /* Normal code (CP).  */
01161                      next_byte (&(ieee->h));
01162                      section->flags |= SEC_CODE;
01163                      break;
01164                     case 0xC4:     /* Normal data (CD).  */
01165                      next_byte (&(ieee->h));
01166                      section->flags |= SEC_DATA;
01167                      break;
01168                     case 0xD2:     /* Normal rom data (CR).  */
01169                      next_byte (&(ieee->h));
01170                      section->flags |= SEC_ROM | SEC_DATA;
01171                      break;
01172                     default:
01173                      break;
01174                     }
01175                 }
01176 
01177               /* Read section name, use it if non empty.  */
01178               name = read_id (&ieee->h);
01179               if (name[0])
01180                 section->name = name;
01181 
01182               /* Skip these fields, which we don't care about.  */
01183               {
01184                 bfd_vma parent, brother, context;
01185 
01186                 parse_int (&(ieee->h), &parent);
01187                 parse_int (&(ieee->h), &brother);
01188                 parse_int (&(ieee->h), &context);
01189               }
01190              }
01191              break;
01192            case ieee_section_alignment_enum:
01193              {
01194               unsigned int section_index;
01195               bfd_vma value;
01196               asection *section;
01197 
01198               next_byte (&(ieee->h));
01199               section_index = must_parse_int (&ieee->h);
01200               section = get_section_entry (abfd, ieee, section_index);
01201               if (section_index > ieee->section_count)
01202                 ieee->section_count = section_index;
01203 
01204               section->alignment_power =
01205                 bfd_log2 (must_parse_int (&ieee->h));
01206               (void) parse_int (&(ieee->h), &value);
01207              }
01208              break;
01209            case ieee_e2_first_byte_enum:
01210              {
01211               asection *section;
01212               ieee_record_enum_type t;
01213 
01214               t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
01215               switch (t)
01216                 {
01217                 case ieee_section_size_enum:
01218                   section = ieee->section_table[must_parse_int (&(ieee->h))];
01219                   section->size = must_parse_int (&(ieee->h));
01220                   break;
01221                 case ieee_physical_region_size_enum:
01222                   section = ieee->section_table[must_parse_int (&(ieee->h))];
01223                   section->size = must_parse_int (&(ieee->h));
01224                   break;
01225                 case ieee_region_base_address_enum:
01226                   section = ieee->section_table[must_parse_int (&(ieee->h))];
01227                   section->vma = must_parse_int (&(ieee->h));
01228                   section->lma = section->vma;
01229                   break;
01230                 case ieee_mau_size_enum:
01231                   must_parse_int (&(ieee->h));
01232                   must_parse_int (&(ieee->h));
01233                   break;
01234                 case ieee_m_value_enum:
01235                   must_parse_int (&(ieee->h));
01236                   must_parse_int (&(ieee->h));
01237                   break;
01238                 case ieee_section_base_address_enum:
01239                   section = ieee->section_table[must_parse_int (&(ieee->h))];
01240                   section->vma = must_parse_int (&(ieee->h));
01241                   section->lma = section->vma;
01242                   break;
01243                 case ieee_section_offset_enum:
01244                   (void) must_parse_int (&(ieee->h));
01245                   (void) must_parse_int (&(ieee->h));
01246                   break;
01247                 default:
01248                   return;
01249                 }
01250              }
01251              break;
01252            default:
01253              return;
01254            }
01255        }
01256     }
01257 }
01258 
01259 /* Make a section for the debugging information, if any.  We don't try
01260    to interpret the debugging information; we just point the section
01261    at the area in the file so that program which understand can dig it
01262    out.  */
01263 
01264 static bfd_boolean
01265 ieee_slurp_debug (bfd *abfd)
01266 {
01267   ieee_data_type *ieee = IEEE_DATA (abfd);
01268   asection *sec;
01269   file_ptr debug_end;
01270   flagword flags;
01271 
01272   if (ieee->w.r.debug_information_part == 0)
01273     return TRUE;
01274 
01275   flags = SEC_DEBUGGING | SEC_HAS_CONTENTS;
01276   sec = bfd_make_section_with_flags (abfd, ".debug", flags);
01277   if (sec == NULL)
01278     return FALSE;
01279   sec->filepos = ieee->w.r.debug_information_part;
01280 
01281   debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
01282   sec->size = debug_end - ieee->w.r.debug_information_part;
01283 
01284   return TRUE;
01285 }
01286 
01287 /* Archive stuff.  */
01288 
01289 static const bfd_target *
01290 ieee_archive_p (bfd *abfd)
01291 {
01292   char *library;
01293   unsigned int i;
01294   unsigned char buffer[512];
01295   file_ptr buffer_offset = 0;
01296   ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
01297   ieee_ar_data_type *ieee;
01298   bfd_size_type alc_elts;
01299   ieee_ar_obstack_type *elts = NULL;
01300   bfd_size_type amt = sizeof (ieee_ar_data_type);
01301 
01302   abfd->tdata.ieee_ar_data = bfd_alloc (abfd, amt);
01303   if (!abfd->tdata.ieee_ar_data)
01304     goto error_ret_restore;
01305   ieee = IEEE_AR_DATA (abfd);
01306 
01307   /* Ignore the return value here.  It doesn't matter if we don't read
01308      the entire buffer.  We might have a very small ieee file.  */
01309   bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
01310 
01311   ieee->h.first_byte = buffer;
01312   ieee->h.input_p = buffer;
01313 
01314   ieee->h.abfd = abfd;
01315 
01316   if (this_byte (&(ieee->h)) != Module_Beginning)
01317     goto got_wrong_format_error;
01318 
01319   next_byte (&(ieee->h));
01320   library = read_id (&(ieee->h));
01321   if (strcmp (library, "LIBRARY") != 0)
01322     goto got_wrong_format_error;
01323 
01324   /* Throw away the filename.  */
01325   read_id (&(ieee->h));
01326 
01327   ieee->element_count = 0;
01328   ieee->element_index = 0;
01329 
01330   next_byte (&(ieee->h));   /* Drop the ad part.  */
01331   must_parse_int (&(ieee->h));     /* And the two dummy numbers.  */
01332   must_parse_int (&(ieee->h));
01333 
01334   alc_elts = 10;
01335   elts = bfd_malloc (alc_elts * sizeof *elts);
01336   if (elts == NULL)
01337     goto error_return;
01338 
01339   /* Read the index of the BB table.  */
01340   while (1)
01341     {
01342       int rec;
01343       ieee_ar_obstack_type *t;
01344 
01345       rec = read_2bytes (&(ieee->h));
01346       if (rec != (int) ieee_assign_value_to_variable_enum)
01347        break;
01348 
01349       if (ieee->element_count >= alc_elts)
01350        {
01351          ieee_ar_obstack_type *n;
01352 
01353          alc_elts *= 2;
01354          n = bfd_realloc (elts, alc_elts * sizeof (* elts));
01355          if (n == NULL)
01356            goto error_return;
01357          elts = n;
01358        }
01359 
01360       t = &elts[ieee->element_count];
01361       ieee->element_count++;
01362 
01363       must_parse_int (&(ieee->h));
01364       t->file_offset = must_parse_int (&(ieee->h));
01365       t->abfd = (bfd *) NULL;
01366 
01367       /* Make sure that we don't go over the end of the buffer.  */
01368       if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
01369        {
01370          /* Past half way, reseek and reprime.  */
01371          buffer_offset += ieee_pos (IEEE_DATA (abfd));
01372          if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
01373            goto error_return;
01374 
01375          /* Again ignore return value of bfd_bread.  */
01376          bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
01377          ieee->h.first_byte = buffer;
01378          ieee->h.input_p = buffer;
01379        }
01380     }
01381 
01382   amt = ieee->element_count;
01383   amt *= sizeof *ieee->elements;
01384   ieee->elements = bfd_alloc (abfd, amt);
01385   if (ieee->elements == NULL)
01386     goto error_return;
01387 
01388   memcpy (ieee->elements, elts, (size_t) amt);
01389   free (elts);
01390   elts = NULL;
01391 
01392   /* Now scan the area again, and replace BB offsets with file offsets.  */
01393   for (i = 2; i < ieee->element_count; i++)
01394     {
01395       if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
01396        goto error_return;
01397 
01398       /* Again ignore return value of bfd_bread.  */
01399       bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
01400       ieee->h.first_byte = buffer;
01401       ieee->h.input_p = buffer;
01402 
01403       next_byte (&(ieee->h));             /* Drop F8.  */
01404       next_byte (&(ieee->h));             /* Drop 14.  */
01405       must_parse_int (&(ieee->h)); /* Drop size of block.  */
01406 
01407       if (must_parse_int (&(ieee->h)) != 0)
01408        /* This object has been deleted.  */
01409        ieee->elements[i].file_offset = 0;
01410       else
01411        ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
01412     }
01413 
01414   /*  abfd->has_armap = ;*/
01415 
01416   return abfd->xvec;
01417 
01418  got_wrong_format_error:
01419   bfd_set_error (bfd_error_wrong_format);
01420  error_return:
01421   if (elts != NULL)
01422     free (elts);
01423   bfd_release (abfd, ieee);
01424  error_ret_restore:
01425   abfd->tdata.ieee_ar_data = save;
01426 
01427   return NULL;
01428 }
01429 
01430 static bfd_boolean
01431 ieee_mkobject (bfd *abfd)
01432 {
01433   bfd_size_type amt;
01434 
01435   output_ptr_start = NULL;
01436   output_ptr = NULL;
01437   output_ptr_end = NULL;
01438   input_ptr_start = NULL;
01439   input_ptr = NULL;
01440   input_ptr_end = NULL;
01441   input_bfd = NULL;
01442   output_bfd = NULL;
01443   output_buffer = 0;
01444   amt = sizeof (ieee_data_type);
01445   abfd->tdata.ieee_data = bfd_zalloc (abfd, amt);
01446   return abfd->tdata.ieee_data != NULL;
01447 }
01448 
01449 static bfd_boolean
01450 do_one (ieee_data_type *ieee,
01451        ieee_per_section_type *current_map,
01452        unsigned char *location_ptr,
01453        asection *s,
01454        int iterations)
01455 {
01456   switch (this_byte (&(ieee->h)))
01457     {
01458     case ieee_load_constant_bytes_enum:
01459       {
01460        unsigned int number_of_maus;
01461        unsigned int i;
01462 
01463        next_byte (&(ieee->h));
01464        number_of_maus = must_parse_int (&(ieee->h));
01465 
01466        for (i = 0; i < number_of_maus; i++)
01467          {
01468            location_ptr[current_map->pc++] = this_byte (&(ieee->h));
01469            next_byte (&(ieee->h));
01470          }
01471       }
01472       break;
01473 
01474     case ieee_load_with_relocation_enum:
01475       {
01476        bfd_boolean loop = TRUE;
01477 
01478        next_byte (&(ieee->h));
01479        while (loop)
01480          {
01481            switch (this_byte (&(ieee->h)))
01482              {
01483              case ieee_variable_R_enum:
01484 
01485              case ieee_function_signed_open_b_enum:
01486              case ieee_function_unsigned_open_b_enum:
01487              case ieee_function_either_open_b_enum:
01488               {
01489                 unsigned int extra = 4;
01490                 bfd_boolean pcrel = FALSE;
01491                 asection *section;
01492                 ieee_reloc_type *r;
01493 
01494                 r = bfd_alloc (ieee->h.abfd, sizeof (* r));
01495                 if (!r)
01496                   return FALSE;
01497 
01498                 *(current_map->reloc_tail_ptr) = r;
01499                 current_map->reloc_tail_ptr = &r->next;
01500                 r->next = (ieee_reloc_type *) NULL;
01501                 next_byte (&(ieee->h));
01502 /*                       abort();*/
01503                 r->relent.sym_ptr_ptr = 0;
01504                 parse_expression (ieee,
01505                                 &r->relent.addend,
01506                                 &r->symbol,
01507                                 &pcrel, &extra, &section);
01508                 r->relent.address = current_map->pc;
01509                 s->flags |= SEC_RELOC;
01510                 s->owner->flags |= HAS_RELOC;
01511                 s->reloc_count++;
01512                 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
01513                   r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
01514 
01515                 if (this_byte (&(ieee->h)) == (int) ieee_comma)
01516                   {
01517                     next_byte (&(ieee->h));
01518                     /* Fetch number of bytes to pad.  */
01519                     extra = must_parse_int (&(ieee->h));
01520                   };
01521 
01522                 switch (this_byte (&(ieee->h)))
01523                   {
01524                   case ieee_function_signed_close_b_enum:
01525                     next_byte (&(ieee->h));
01526                     break;
01527                   case ieee_function_unsigned_close_b_enum:
01528                     next_byte (&(ieee->h));
01529                     break;
01530                   case ieee_function_either_close_b_enum:
01531                     next_byte (&(ieee->h));
01532                     break;
01533                   default:
01534                     break;
01535                   }
01536                 /* Build a relocation entry for this type.  */
01537                 /* If pc rel then stick -ve pc into instruction
01538                    and take out of reloc ..
01539 
01540                    I've changed this. It's all too complicated. I
01541                    keep 0 in the instruction now.  */
01542 
01543                 switch (extra)
01544                   {
01545                   case 0:
01546                   case 4:
01547 
01548                     if (pcrel)
01549                      {
01550 #if KEEPMINUSPCININST
01551                        bfd_put_32 (ieee->h.abfd, -current_map->pc,
01552                                   location_ptr + current_map->pc);
01553                        r->relent.howto = &rel32_howto;
01554                        r->relent.addend -= current_map->pc;
01555 #else
01556                        bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
01557                                   current_map->pc);
01558                        r->relent.howto = &rel32_howto;
01559 #endif
01560                      }
01561                     else
01562                      {
01563                        bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
01564                                   location_ptr + current_map->pc);
01565                        r->relent.howto = &abs32_howto;
01566                      }
01567                     current_map->pc += 4;
01568                     break;
01569                   case 2:
01570                     if (pcrel)
01571                      {
01572 #if KEEPMINUSPCININST
01573                        bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
01574                                   location_ptr + current_map->pc);
01575                        r->relent.addend -= current_map->pc;
01576                        r->relent.howto = &rel16_howto;
01577 #else
01578 
01579                        bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
01580                                   location_ptr + current_map->pc);
01581                        r->relent.howto = &rel16_howto;
01582 #endif
01583                      }
01584 
01585                     else
01586                      {
01587                        bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
01588                                   location_ptr + current_map->pc);
01589                        r->relent.howto = &abs16_howto;
01590                      }
01591                     current_map->pc += 2;
01592                     break;
01593                   case 1:
01594                     if (pcrel)
01595                      {
01596 #if KEEPMINUSPCININST
01597                        bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
01598                        r->relent.addend -= current_map->pc;
01599                        r->relent.howto = &rel8_howto;
01600 #else
01601                        bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
01602                        r->relent.howto = &rel8_howto;
01603 #endif
01604                      }
01605                     else
01606                      {
01607                        bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
01608                        r->relent.howto = &abs8_howto;
01609                      }
01610                     current_map->pc += 1;
01611                     break;
01612 
01613                   default:
01614                     BFD_FAIL ();
01615                     return FALSE;
01616                   }
01617               }
01618               break;
01619              default:
01620               {
01621                 bfd_vma this_size;
01622 
01623                 if (parse_int (&(ieee->h), &this_size))
01624                   {
01625                     unsigned int i;
01626 
01627                     for (i = 0; i < this_size; i++)
01628                      {
01629                        location_ptr[current_map->pc++] = this_byte (&(ieee->h));
01630                        next_byte (&(ieee->h));
01631                      }
01632                   }
01633                 else
01634                   loop = FALSE;
01635               }
01636              }
01637 
01638            /* Prevent more than the first load-item of an LR record
01639               from being repeated (MRI convention).  */
01640            if (iterations != 1)
01641              loop = FALSE;
01642          }
01643       }
01644     }
01645   return TRUE;
01646 }
01647 
01648 /* Read in all the section data and relocation stuff too.  */
01649 
01650 static bfd_boolean
01651 ieee_slurp_section_data (bfd *abfd)
01652 {
01653   bfd_byte *location_ptr = (bfd_byte *) NULL;
01654   ieee_data_type *ieee = IEEE_DATA (abfd);
01655   unsigned int section_number;
01656   ieee_per_section_type *current_map = NULL;
01657   asection *s;
01658   
01659   /* Seek to the start of the data area.  */
01660   if (ieee->read_data)
01661     return TRUE;
01662   ieee->read_data = TRUE;
01663   ieee_seek (ieee, ieee->w.r.data_part);
01664 
01665   /* Allocate enough space for all the section contents.  */
01666   for (s = abfd->sections; s != (asection *) NULL; s = s->next)
01667     {
01668       ieee_per_section_type *per = ieee_per_section (s);
01669       arelent **relpp;
01670 
01671       if ((s->flags & SEC_DEBUGGING) != 0)
01672        continue;
01673       per->data = bfd_alloc (ieee->h.abfd, s->size);
01674       if (!per->data)
01675        return FALSE;
01676       relpp = &s->relocation;
01677       per->reloc_tail_ptr = (ieee_reloc_type **) relpp;
01678     }
01679 
01680   while (TRUE)
01681     {
01682       switch (this_byte (&(ieee->h)))
01683        {
01684          /* IF we see anything strange then quit.  */
01685        default:
01686          return TRUE;
01687 
01688        case ieee_set_current_section_enum:
01689          next_byte (&(ieee->h));
01690          section_number = must_parse_int (&(ieee->h));
01691          s = ieee->section_table[section_number];
01692          s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
01693          current_map = ieee_per_section (s);
01694          location_ptr = current_map->data - s->vma;
01695          /* The document I have says that Microtec's compilers reset
01696             this after a sec section, even though the standard says not
01697             to, SO...  */
01698          current_map->pc = s->vma;
01699          break;
01700 
01701        case ieee_e2_first_byte_enum:
01702          next_byte (&(ieee->h));
01703          switch (this_byte (&(ieee->h)))
01704            {
01705            case ieee_set_current_pc_enum & 0xff:
01706              {
01707               bfd_vma value;
01708               ieee_symbol_index_type symbol;
01709               unsigned int extra;
01710               bfd_boolean pcrel;
01711 
01712               next_byte (&(ieee->h));
01713               must_parse_int (&(ieee->h));       /* Throw away section #.  */
01714               parse_expression (ieee, &value,
01715                               &symbol,
01716                               &pcrel, &extra,
01717                               0);
01718               current_map->pc = value;
01719               BFD_ASSERT ((unsigned) (value - s->vma) <= s->size);
01720              }
01721              break;
01722 
01723            case ieee_value_starting_address_enum & 0xff:
01724              next_byte (&(ieee->h));
01725              if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
01726               next_byte (&(ieee->h));
01727              abfd->start_address = must_parse_int (&(ieee->h));
01728              /* We've got to the end of the data now -  */
01729              return TRUE;
01730            default:
01731              BFD_FAIL ();
01732              return FALSE;
01733            }
01734          break;
01735        case ieee_repeat_data_enum:
01736          {
01737            /* Repeat the following LD or LR n times - we do this by
01738               remembering the stream pointer before running it and
01739               resetting it and running it n times. We special case
01740               the repetition of a repeat_data/load_constant.  */
01741            unsigned int iterations;
01742            unsigned char *start;
01743 
01744            next_byte (&(ieee->h));
01745            iterations = must_parse_int (&(ieee->h));
01746            start = ieee->h.input_p;
01747            if (start[0] == (int) ieee_load_constant_bytes_enum
01748               && start[1] == 1)
01749              {
01750               while (iterations != 0)
01751                 {
01752                   location_ptr[current_map->pc++] = start[2];
01753                   iterations--;
01754                 }
01755               next_byte (&(ieee->h));
01756               next_byte (&(ieee->h));
01757               next_byte (&(ieee->h));
01758              }
01759            else
01760              {
01761               while (iterations != 0)
01762                 {
01763                   ieee->h.input_p = start;
01764                   if (!do_one (ieee, current_map, location_ptr, s,
01765                              (int) iterations))
01766                     return FALSE;
01767                   iterations--;
01768                 }
01769              }
01770          }
01771          break;
01772        case ieee_load_constant_bytes_enum:
01773        case ieee_load_with_relocation_enum:
01774          if (!do_one (ieee, current_map, location_ptr, s, 1))
01775            return FALSE;
01776        }
01777     }
01778 }
01779 
01780 static const bfd_target *
01781 ieee_object_p (bfd *abfd)
01782 {
01783   char *processor;
01784   unsigned int part;
01785   ieee_data_type *ieee;
01786   unsigned char buffer[300];
01787   ieee_data_type *save = IEEE_DATA (abfd);
01788   bfd_size_type amt;
01789 
01790   abfd->tdata.ieee_data = 0;
01791   ieee_mkobject (abfd);
01792 
01793   ieee = IEEE_DATA (abfd);
01794   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
01795     goto fail;
01796   /* Read the first few bytes in to see if it makes sense.  Ignore
01797      bfd_bread return value;  The file might be very small.  */
01798   bfd_bread ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd);
01799 
01800   ieee->h.input_p = buffer;
01801   if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
01802     goto got_wrong_format;
01803 
01804   ieee->read_symbols = FALSE;
01805   ieee->read_data = FALSE;
01806   ieee->section_count = 0;
01807   ieee->external_symbol_max_index = 0;
01808   ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
01809   ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
01810   ieee->external_reference_max_index = 0;
01811   ieee->h.abfd = abfd;
01812   ieee->section_table = NULL;
01813   ieee->section_table_size = 0;
01814 
01815   processor = ieee->mb.processor = read_id (&(ieee->h));
01816   if (strcmp (processor, "LIBRARY") == 0)
01817     goto got_wrong_format;
01818   ieee->mb.module_name = read_id (&(ieee->h));
01819   if (abfd->filename == (const char *) NULL)
01820     abfd->filename = ieee->mb.module_name;
01821 
01822   /* Determine the architecture and machine type of the object file.  */
01823   {
01824     const bfd_arch_info_type *arch;
01825     char family[10];
01826 
01827     /* IEEE does not specify the format of the processor identification
01828        string, so the compiler is free to put in it whatever it wants.
01829        We try here to recognize different processors belonging to the
01830        m68k family.  Code for other processors can be added here.  */
01831     if ((processor[0] == '6') && (processor[1] == '8'))
01832       {
01833        if (processor[2] == '3')        /* 683xx integrated processors.  */
01834          {
01835            switch (processor[3])
01836              {
01837              case '0':                        /* 68302, 68306, 68307 */
01838              case '2':                        /* 68322, 68328 */
01839              case '5':                        /* 68356 */
01840               strcpy (family, "68000");   /* MC68000-based controllers.  */
01841               break;
01842 
01843              case '3':                        /* 68330, 68331, 68332, 68333,
01844                                           68334, 68335, 68336, 68338 */
01845              case '6':                        /* 68360 */
01846              case '7':                        /* 68376 */
01847               strcpy (family, "68332");   /* CPU32 and CPU32+ */
01848               break;
01849 
01850              case '4':
01851               if (processor[4] == '9')    /* 68349 */
01852                 strcpy (family, "68030"); /* CPU030 */
01853               else                      /* 68340, 68341 */
01854                 strcpy (family, "68332"); /* CPU32 and CPU32+ */
01855               break;
01856 
01857              default:                         /* Does not exist yet.  */
01858               strcpy (family, "68332");   /* Guess it will be CPU32 */
01859              }
01860          }
01861        else if (TOUPPER (processor[3]) == 'F')  /* 68F333 */
01862          strcpy (family, "68332");            /* CPU32 */
01863        else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers.  */
01864                && ((TOUPPER (processor[2]) == 'E')
01865                    || (TOUPPER (processor[2]) == 'H')
01866                    || (TOUPPER (processor[2]) == 'L')))
01867          {
01868            strcpy (family, "68");
01869            strncat (family, processor + 4, 7);
01870            family[9] = '\0';
01871          }
01872        else                         /* "Regular" processors.  */
01873          {
01874            strncpy (family, processor, 9);
01875            family[9] = '\0';
01876          }
01877       }
01878     else if ((CONST_STRNEQ (processor, "cpu32")) /* CPU32 and CPU32+  */
01879             || (CONST_STRNEQ (processor, "CPU32")))
01880       strcpy (family, "68332");
01881     else
01882       {
01883        strncpy (family, processor, 9);
01884        family[9] = '\0';
01885       }
01886 
01887     arch = bfd_scan_arch (family);
01888     if (arch == 0)
01889       goto got_wrong_format;
01890     abfd->arch_info = arch;
01891   }
01892 
01893   if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
01894     goto fail;
01895 
01896   next_byte (&(ieee->h));
01897 
01898   if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
01899     goto fail;
01900 
01901   if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
01902     goto fail;
01903 
01904   /* If there is a byte order info, take it.  */
01905   if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum
01906       || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
01907     next_byte (&(ieee->h));
01908 
01909   for (part = 0; part < N_W_VARIABLES; part++)
01910     {
01911       bfd_boolean ok;
01912 
01913       if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
01914        goto fail;
01915 
01916       if (this_byte_and_next (&(ieee->h)) != part)
01917        goto fail;
01918 
01919       ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
01920       if (! ok)
01921        goto fail;
01922     }
01923 
01924   if (ieee->w.r.external_part != 0)
01925     abfd->flags = HAS_SYMS;
01926 
01927   /* By now we know that this is a real IEEE file, we're going to read
01928      the whole thing into memory so that we can run up and down it
01929      quickly.  We can work out how big the file is from the trailer
01930      record.  */
01931 
01932   amt = ieee->w.r.me_record + 1;
01933   IEEE_DATA (abfd)->h.first_byte = bfd_alloc (ieee->h.abfd, amt);
01934   if (!IEEE_DATA (abfd)->h.first_byte)
01935     goto fail;
01936   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
01937     goto fail;
01938   /* FIXME: Check return value.  I'm not sure whether it needs to read
01939      the entire buffer or not.  */
01940   bfd_bread ((void *) (IEEE_DATA (abfd)->h.first_byte),
01941            (bfd_size_type) ieee->w.r.me_record + 1, abfd);
01942 
01943   ieee_slurp_sections (abfd);
01944 
01945   if (! ieee_slurp_debug (abfd))
01946     goto fail;
01947 
01948   /* Parse section data to activate file and section flags implied by
01949      section contents.  */
01950   if (! ieee_slurp_section_data (abfd))
01951     goto fail;
01952 
01953   return abfd->xvec;
01954 got_wrong_format:
01955   bfd_set_error (bfd_error_wrong_format);
01956 fail:
01957   bfd_release (abfd, ieee);
01958   abfd->tdata.ieee_data = save;
01959   return (const bfd_target *) NULL;
01960 }
01961 
01962 static void
01963 ieee_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED,
01964                     asymbol *symbol,
01965                     symbol_info *ret)
01966 {
01967   bfd_symbol_info (symbol, ret);
01968   if (symbol->name[0] == ' ')
01969     ret->name = "* empty table entry ";
01970   if (!symbol->section)
01971     ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
01972 }
01973 
01974 static void
01975 ieee_print_symbol (bfd *abfd,
01976                  void * afile,
01977                  asymbol *symbol,
01978                  bfd_print_symbol_type how)
01979 {
01980   FILE *file = (FILE *) afile;
01981 
01982   switch (how)
01983     {
01984     case bfd_print_symbol_name:
01985       fprintf (file, "%s", symbol->name);
01986       break;
01987     case bfd_print_symbol_more:
01988       BFD_FAIL ();
01989       break;
01990     case bfd_print_symbol_all:
01991       {
01992        const char *section_name =
01993          (symbol->section == (asection *) NULL
01994           ? "*abs"
01995           : symbol->section->name);
01996 
01997        if (symbol->name[0] == ' ')
01998          fprintf (file, "* empty table entry ");
01999        else
02000          {
02001            bfd_print_symbol_vandf (abfd, (void *) file, symbol);
02002 
02003            fprintf (file, " %-5s %04x %02x %s",
02004                    section_name,
02005                    (unsigned) ieee_symbol (symbol)->index,
02006                    (unsigned) 0,
02007                    symbol->name);
02008          }
02009       }
02010       break;
02011     }
02012 }
02013 
02014 static bfd_boolean
02015 ieee_new_section_hook (bfd *abfd, asection *newsect)
02016 {
02017   if (!newsect->used_by_bfd)
02018     {
02019       newsect->used_by_bfd = bfd_alloc (abfd, sizeof (ieee_per_section_type));
02020       if (!newsect->used_by_bfd)
02021        return FALSE;
02022     }
02023   ieee_per_section (newsect)->data = NULL;
02024   ieee_per_section (newsect)->section = newsect;
02025   return _bfd_generic_new_section_hook (abfd, newsect);
02026 }
02027 
02028 static long
02029 ieee_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
02030 {
02031   if ((asect->flags & SEC_DEBUGGING) != 0)
02032     return 0;
02033   if (! ieee_slurp_section_data (abfd))
02034     return -1;
02035   return (asect->reloc_count + 1) * sizeof (arelent *);
02036 }
02037 
02038 static bfd_boolean
02039 ieee_get_section_contents (bfd *abfd,
02040                         sec_ptr section,
02041                         void * location,
02042                         file_ptr offset,
02043                         bfd_size_type count)
02044 {
02045   ieee_per_section_type *p = ieee_per_section (section);
02046   if ((section->flags & SEC_DEBUGGING) != 0)
02047     return _bfd_generic_get_section_contents (abfd, section, location,
02048                                          offset, count);
02049   ieee_slurp_section_data (abfd);
02050   (void) memcpy ((void *) location, (void *) (p->data + offset), (unsigned) count);
02051   return TRUE;
02052 }
02053 
02054 static long
02055 ieee_canonicalize_reloc (bfd *abfd,
02056                       sec_ptr section,
02057                       arelent **relptr,
02058                       asymbol **symbols)
02059 {
02060   ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
02061   ieee_data_type *ieee = IEEE_DATA (abfd);
02062 
02063   if ((section->flags & SEC_DEBUGGING) != 0)
02064     return 0;
02065 
02066   while (src != (ieee_reloc_type *) NULL)
02067     {
02068       /* Work out which symbol to attach it this reloc to.  */
02069       switch (src->symbol.letter)
02070        {
02071        case 'I':
02072          src->relent.sym_ptr_ptr =
02073            symbols + src->symbol.index + ieee->external_symbol_base_offset;
02074          break;
02075        case 'X':
02076          src->relent.sym_ptr_ptr =
02077            symbols + src->symbol.index + ieee->external_reference_base_offset;
02078          break;
02079        case 0:
02080          if (src->relent.sym_ptr_ptr != NULL)
02081            src->relent.sym_ptr_ptr =
02082              src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
02083          break;
02084        default:
02085 
02086          BFD_FAIL ();
02087        }
02088       *relptr++ = &src->relent;
02089       src = src->next;
02090     }
02091   *relptr = NULL;
02092   return section->reloc_count;
02093 }
02094 
02095 static int
02096 comp (const void * ap, const void * bp)
02097 {
02098   arelent *a = *((arelent **) ap);
02099   arelent *b = *((arelent **) bp);
02100   return a->address - b->address;
02101 }
02102 
02103 /* Write the section headers.  */
02104 
02105 static bfd_boolean
02106 ieee_write_section_part (bfd *abfd)
02107 {
02108   ieee_data_type *ieee = IEEE_DATA (abfd);
02109   asection *s;
02110 
02111   ieee->w.r.section_part = bfd_tell (abfd);
02112   for (s = abfd->sections; s != (asection *) NULL; s = s->next)
02113     {
02114       if (! bfd_is_abs_section (s)
02115          && (s->flags & SEC_DEBUGGING) == 0)
02116        {
02117          if (! ieee_write_byte (abfd, ieee_section_type_enum)
02118              || ! ieee_write_byte (abfd,
02119                                 (bfd_byte) (s->index
02120                                           + IEEE_SECTION_NUMBER_BASE)))
02121            return FALSE;
02122 
02123          if (abfd->flags & EXEC_P)
02124            {
02125              /* This image is executable, so output absolute sections.  */
02126              if (! ieee_write_byte (abfd, ieee_variable_A_enum)
02127                 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
02128               return FALSE;
02129            }
02130          else
02131            {
02132              if (! ieee_write_byte (abfd, ieee_variable_C_enum))
02133               return FALSE;
02134            }
02135 
02136          switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
02137            {
02138            case SEC_CODE | SEC_LOAD:
02139            case SEC_CODE:
02140              if (! ieee_write_byte (abfd, ieee_variable_P_enum))
02141               return FALSE;
02142              break;
02143            case SEC_DATA:
02144            default:
02145              if (! ieee_write_byte (abfd, ieee_variable_D_enum))
02146               return FALSE;
02147              break;
02148            case SEC_ROM:
02149            case SEC_ROM | SEC_DATA:
02150            case SEC_ROM | SEC_LOAD:
02151            case SEC_ROM | SEC_DATA | SEC_LOAD:
02152              if (! ieee_write_byte (abfd, ieee_variable_R_enum))
02153               return FALSE;
02154            }
02155 
02156 
02157          if (! ieee_write_id (abfd, s->name))
02158            return FALSE;
02159          /* Alignment.  */
02160          if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
02161              || ! ieee_write_byte (abfd,
02162                                 (bfd_byte) (s->index
02163                                           + IEEE_SECTION_NUMBER_BASE))
02164              || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
02165            return FALSE;
02166 
02167          /* Size.  */
02168          if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
02169              || ! ieee_write_byte (abfd,
02170                                 (bfd_byte) (s->index
02171                                           + IEEE_SECTION_NUMBER_BASE))
02172              || ! ieee_write_int (abfd, s->size))
02173            return FALSE;
02174          if (abfd->flags & EXEC_P)
02175            {
02176              /* Relocateable sections don't have asl records.  */
02177              /* Vma.  */
02178              if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
02179                 || ! ieee_write_byte (abfd,
02180                                    ((bfd_byte)
02181                                     (s->index
02182                                      + IEEE_SECTION_NUMBER_BASE)))
02183                 || ! ieee_write_int (abfd, s->lma))
02184               return FALSE;
02185            }
02186        }
02187     }
02188 
02189   return TRUE;
02190 }
02191 
02192 static bfd_boolean
02193 do_with_relocs (bfd *abfd, asection *s)
02194 {
02195   unsigned int number_of_maus_in_address =
02196     bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
02197   unsigned int relocs_to_go = s->reloc_count;
02198   bfd_byte *stream = ieee_per_section (s)->data;
02199   arelent **p = s->orelocation;
02200   bfd_size_type current_byte_index = 0;
02201 
02202   qsort (s->orelocation,
02203         relocs_to_go,
02204         sizeof (arelent **),
02205         comp);
02206 
02207   /* Output the section preheader.  */
02208   if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
02209       || ! ieee_write_byte (abfd,
02210                          (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
02211       || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
02212       || ! ieee_write_byte (abfd,
02213                          (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
02214     return FALSE;
02215 
02216   if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
02217     {
02218       if (! ieee_write_int (abfd, s->lma))
02219        return FALSE;
02220     }
02221   else
02222     {
02223       if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
02224        return FALSE;
02225     }
02226 
02227   if (relocs_to_go == 0)
02228     {
02229       /* If there aren't any relocations then output the load constant
02230         byte opcode rather than the load with relocation opcode.  */
02231       while (current_byte_index < s->size)
02232        {
02233          bfd_size_type run;
02234          unsigned int MAXRUN = 127;
02235 
02236          run = MAXRUN;
02237          if (run > s->size - current_byte_index)
02238            run = s->size - current_byte_index;
02239 
02240          if (run != 0)
02241            {
02242              if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
02243               return FALSE;
02244              /* Output a stream of bytes.  */
02245              if (! ieee_write_int (abfd, run))
02246               return FALSE;
02247              if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
02248                 != run)
02249               return FALSE;
02250              current_byte_index += run;
02251            }
02252        }
02253     }
02254   else
02255     {
02256       if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
02257        return FALSE;
02258 
02259       /* Output the data stream as the longest sequence of bytes
02260         possible, allowing for the a reasonable packet size and
02261         relocation stuffs.  */
02262       if (stream == NULL)
02263        {
02264          /* Outputting a section without data, fill it up.  */
02265          stream = bfd_zalloc (abfd, s->size);
02266          if (!stream)
02267            return FALSE;
02268        }
02269       while (current_byte_index < s->size)
02270        {
02271          bfd_size_type run;
02272          unsigned int MAXRUN = 127;
02273 
02274          if (relocs_to_go)
02275            {
02276              run = (*p)->address - current_byte_index;
02277              if (run > MAXRUN)
02278               run = MAXRUN;
02279            }
02280          else
02281            run = MAXRUN;
02282 
02283          if (run > s->size - current_byte_index)
02284            run = s->size - current_byte_index;
02285 
02286          if (run != 0)
02287            {
02288              /* Output a stream of bytes.  */
02289              if (! ieee_write_int (abfd, run))
02290               return FALSE;
02291              if (bfd_bwrite ((void *) (stream + current_byte_index), run, abfd)
02292                 != run)
02293               return FALSE;
02294              current_byte_index += run;
02295            }
02296 
02297          /* Output any relocations here.  */
02298          if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
02299            {
02300              while (relocs_to_go
02301                    && (*p) && (*p)->address == current_byte_index)
02302               {
02303                 arelent *r = *p;
02304                 bfd_signed_vma ov;
02305                 switch (r->howto->size)
02306                   {
02307                   case 2:
02308                     ov = bfd_get_signed_32 (abfd,
02309                                          stream + current_byte_index);
02310                     current_byte_index += 4;
02311                     break;
02312                   case 1:
02313                     ov = bfd_get_signed_16 (abfd,
02314                                          stream + current_byte_index);
02315                     current_byte_index += 2;
02316                     break;
02317                   case 0:
02318                     ov = bfd_get_signed_8 (abfd,
02319                                         stream + current_byte_index);
02320                     current_byte_index++;
02321                     break;
02322                   default:
02323                     ov = 0;
02324                     BFD_FAIL ();
02325                     return FALSE;
02326                   }
02327 
02328                 ov &= r->howto->src_mask;
02329 
02330                 if (r->howto->pc_relative
02331                     && ! r->howto->pcrel_offset)
02332                   ov += r->address;
02333 
02334                 if (! ieee_write_byte (abfd,
02335                                     ieee_function_either_open_b_enum))
02336                   return FALSE;
02337 
02338                 if (r->sym_ptr_ptr != (asymbol **) NULL)
02339                   {
02340                     if (! ieee_write_expression (abfd, r->addend + ov,
02341                                              *(r->sym_ptr_ptr),
02342                                              r->howto->pc_relative,
02343                                              (unsigned) s->index))
02344                      return FALSE;
02345                   }
02346                 else
02347                   {
02348                     if (! ieee_write_expression (abfd, r->addend + ov,
02349                                              (asymbol *) NULL,
02350                                              r->howto->pc_relative,
02351                                              (unsigned) s->index))
02352                      return FALSE;
02353                   }
02354 
02355                 if (number_of_maus_in_address
02356                     != bfd_get_reloc_size (r->howto))
02357                   {
02358                     bfd_vma rsize = bfd_get_reloc_size (r->howto);
02359                     if (! ieee_write_int (abfd, rsize))
02360                      return FALSE;
02361                   }
02362                 if (! ieee_write_byte (abfd,
02363                                     ieee_function_either_close_b_enum))
02364                   return FALSE;
02365 
02366                 relocs_to_go--;
02367                 p++;
02368               }
02369 
02370            }
02371        }
02372     }
02373 
02374   return TRUE;
02375 }
02376 
02377 /* If there are no relocations in the output section then we can be
02378    clever about how we write.  We block items up into a max of 127
02379    bytes.  */
02380 
02381 static bfd_boolean
02382 do_as_repeat (bfd *abfd, asection *s)
02383 {
02384   if (s->size)
02385     {
02386       if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
02387          || ! ieee_write_byte (abfd,
02388                             (bfd_byte) (s->index
02389                                        + IEEE_SECTION_NUMBER_BASE))
02390          || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
02391          || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
02392          || ! ieee_write_byte (abfd,
02393                             (bfd_byte) (s->index
02394                                        + IEEE_SECTION_NUMBER_BASE)))
02395        return FALSE;
02396 
02397       if ((abfd->flags & EXEC_P) != 0)
02398        {
02399          if (! ieee_write_int (abfd, s->lma))
02400            return FALSE;
02401        }
02402       else
02403        {
02404          if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
02405            return FALSE;
02406        }
02407 
02408       if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
02409          || ! ieee_write_int (abfd, s->size)
02410          || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
02411          || ! ieee_write_byte (abfd, 1)
02412          || ! ieee_write_byte (abfd, 0))
02413        return FALSE;
02414     }
02415 
02416   return TRUE;
02417 }
02418 
02419 static bfd_boolean
02420 do_without_relocs (bfd *abfd, asection *s)
02421 {
02422   bfd_byte *stream = ieee_per_section (s)->data;
02423 
02424   if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
02425     {
02426       if (! do_as_repeat (abfd, s))
02427        return FALSE;
02428     }
02429   else
02430     {
02431       unsigned int i;
02432 
02433       for (i = 0; i < s->size; i++)
02434        {
02435          if (stream[i] != 0)
02436            {
02437              if (! do_with_relocs (abfd, s))
02438               return FALSE;
02439              return TRUE;
02440            }
02441        }
02442       if (! do_as_repeat (abfd, s))
02443        return FALSE;
02444     }
02445 
02446   return TRUE;
02447 }
02448 
02449 static void
02450 fill (void)
02451 {
02452   bfd_size_type amt = input_ptr_end - input_ptr_start;
02453   /* FIXME: Check return value.  I'm not sure whether it needs to read
02454      the entire buffer or not.  */
02455   bfd_bread ((void *) input_ptr_start, amt, input_bfd);
02456   input_ptr = input_ptr_start;
02457 }
02458 
02459 static void
02460 flush (void)
02461 {
02462   bfd_size_type amt = output_ptr - output_ptr_start;
02463 
02464   if (bfd_bwrite ((void *) (output_ptr_start), amt, output_bfd) != amt)
02465     abort ();
02466   output_ptr = output_ptr_start;
02467   output_buffer++;
02468 }
02469 
02470 #define THIS() ( *input_ptr )
02471 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); }
02472 #define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end)  flush (); }
02473 
02474 static void
02475 write_int (int value)
02476 {
02477   if (value >= 0 && value <= 127)
02478     {
02479       OUT (value);
02480     }
02481   else
02482     {
02483       unsigned int length;
02484 
02485       /* How many significant bytes ?  */
02486       /* FIXME FOR LONGER INTS.  */
02487       if (value & 0xff000000)
02488        length = 4;
02489       else if (value & 0x00ff0000)
02490        length = 3;
02491       else if (value & 0x0000ff00)
02492        length = 2;
02493       else
02494        length = 1;
02495 
02496       OUT ((int) ieee_number_repeat_start_enum + length);
02497       switch (length)
02498        {
02499        case 4:
02500          OUT (value >> 24);
02501        case 3:
02502          OUT (value >> 16);
02503        case 2:
02504          OUT (value >> 8);
02505        case 1:
02506          OUT (value);
02507        }
02508     }
02509 }
02510 
02511 static void
02512 copy_id (void)
02513 {
02514   int length = THIS ();
02515   char ch;
02516 
02517   OUT (length);
02518   NEXT ();
02519   while (length--)
02520     {
02521       ch = THIS ();
02522       OUT (ch);
02523       NEXT ();
02524     }
02525 }
02526 
02527 #define VAR(x) ((x | 0x80))
02528 static void
02529 copy_expression (void)
02530 {
02531   int stack[10];
02532   int *tos = stack;
02533   int value;
02534 
02535   while (1)
02536     {
02537       switch (THIS ())
02538        {
02539        case 0x84:
02540          NEXT ();
02541          value = THIS ();
02542          NEXT ();
02543          value = (value << 8) | THIS ();
02544          NEXT ();
02545          value = (value << 8) | THIS ();
02546          NEXT ();
02547          value = (value << 8) | THIS ();
02548          NEXT ();
02549          *tos++ = value;
02550          break;
02551        case 0x83:
02552          NEXT ();
02553          value = THIS ();
02554          NEXT ();
02555          value = (value << 8) | THIS ();
02556          NEXT ();
02557          value = (value << 8) | THIS ();
02558          NEXT ();
02559          *tos++ = value;
02560          break;
02561        case 0x82:
02562          NEXT ();
02563          value = THIS ();
02564          NEXT ();
02565          value = (value << 8) | THIS ();
02566          NEXT ();
02567          *tos++ = value;
02568          break;
02569        case 0x81:
02570          NEXT ();
02571          value = THIS ();
02572          NEXT ();
02573          *tos++ = value;
02574          break;
02575        case 0x80:
02576          NEXT ();
02577          *tos++ = 0;
02578          break;
02579        default:
02580          if (THIS () > 0x84)
02581            {
02582              /* Not a number, just bug out with the answer.  */
02583              write_int (*(--tos));
02584              return;
02585            }
02586          *tos++ = THIS ();
02587          NEXT ();
02588          break;
02589        case 0xa5:
02590          /* PLUS anything.  */
02591          value = *(--tos);
02592          value += *(--tos);
02593          *tos++ = value;
02594          NEXT ();
02595          break;
02596        case VAR ('R'):
02597          {
02598            int section_number;
02599            ieee_data_type *ieee;
02600            asection *s;
02601 
02602            NEXT ();
02603            section_number = THIS ();
02604 
02605            NEXT ();
02606            ieee = IEEE_DATA (input_bfd);
02607            s = ieee->section_table[section_number];
02608            value = 0;
02609            if (s->output_section)
02610              value = s->output_section->lma;
02611            value += s->output_offset;
02612            *tos++ = value;
02613          }
02614          break;
02615        case 0x90:
02616          {
02617            NEXT ();
02618            write_int (*(--tos));
02619            OUT (0x90);
02620            return;
02621          }
02622        }
02623     }
02624 }
02625 
02626 /* Drop the int in the buffer, and copy a null into the gap, which we
02627    will overwrite later.  */
02628 
02629 static void
02630 fill_int (struct output_buffer_struct *buf)
02631 {
02632   if (buf->buffer == output_buffer)
02633     {
02634       /* Still a chance to output the size.  */
02635       int value = output_ptr - buf->ptrp + 3;
02636       buf->ptrp[0] = value >> 24;
02637       buf->ptrp[1] = value >> 16;
02638       buf->ptrp[2] = value >> 8;
02639       buf->ptrp[3] = value >> 0;
02640     }
02641 }
02642 
02643 static void
02644 drop_int (struct output_buffer_struct *buf)
02645 {
02646   int type = THIS ();
02647   int ch;
02648 
02649   if (type <= 0x84)
02650     {
02651       NEXT ();
02652       switch (type)
02653        {
02654        case 0x84:
02655          ch = THIS ();
02656          NEXT ();
02657        case 0x83:
02658          ch = THIS ();
02659          NEXT ();
02660        case 0x82:
02661          ch = THIS ();
02662          NEXT ();
02663        case 0x81:
02664          ch = THIS ();
02665          NEXT ();
02666        case 0x80:
02667          break;
02668        }
02669     }
02670   OUT (0x84);
02671   buf->ptrp = output_ptr;
02672   buf->buffer = output_buffer;
02673   OUT (0);
02674   OUT (0);
02675   OUT (0);
02676   OUT (0);
02677 }
02678 
02679 static void
02680 copy_int (void)
02681 {
02682   int type = THIS ();
02683   int ch;
02684   if (type <= 0x84)
02685     {
02686       OUT (type);
02687       NEXT ();
02688       switch (type)
02689        {
02690        case 0x84:
02691          ch = THIS ();
02692          NEXT ();
02693          OUT (ch);
02694        case 0x83:
02695          ch = THIS ();
02696          NEXT ();
02697          OUT (ch);
02698        case 0x82:
02699          ch = THIS ();
02700          NEXT ();
02701          OUT (ch);
02702        case 0x81:
02703          ch = THIS ();
02704          NEXT ();
02705          OUT (ch);
02706        case 0x80:
02707          break;
02708        }
02709     }
02710 }
02711 
02712 #define ID      copy_id ()
02713 #define INT     copy_int ()
02714 #define EXP     copy_expression ()
02715 #define INTn(q) copy_int ()
02716 #define EXPn(q) copy_expression ()
02717 
02718 static void
02719 copy_till_end (void)
02720 {
02721   int ch = THIS ();
02722 
02723   while (1)
02724     {
02725       while (ch <= 0x80)
02726        {
02727          OUT (ch);
02728          NEXT ();
02729          ch = THIS ();
02730        }
02731       switch (ch)
02732        {
02733        case 0x84:
02734          OUT (THIS ());
02735          NEXT ();
02736        case 0x83:
02737          OUT (THIS ());
02738          NEXT ();
02739        case 0x82:
02740          OUT (THIS ());
02741          NEXT ();
02742        case 0x81:
02743          OUT (THIS ());
02744          NEXT ();
02745          OUT (THIS ());
02746          NEXT ();
02747 
02748          ch = THIS ();
02749          break;
02750        default:
02751          return;
02752        }
02753     }
02754 
02755 }
02756 
02757 static void
02758 f1_record (void)
02759 {
02760   int ch;
02761 
02762   /* ATN record.  */
02763   NEXT ();
02764   ch = THIS ();
02765   switch (ch)
02766     {
02767     default:
02768       OUT (0xf1);
02769       OUT (ch);
02770       break;
02771     case 0xc9:
02772       NEXT ();
02773       OUT (0xf1);
02774       OUT (0xc9);
02775       INT;
02776       INT;
02777       ch = THIS ();
02778       switch (ch)
02779        {
02780        case 0x16:
02781          NEXT ();
02782          break;
02783        case 0x01:
02784          NEXT ();
02785          break;
02786        case 0x00:
02787          NEXT ();
02788          INT;
02789          break;
02790        case 0x03:
02791          NEXT ();
02792          INT;
02793          break;
02794        case 0x13:
02795          EXPn (instruction address);
02796          break;
02797        default:
02798          break;
02799        }
02800       break;
02801     case 0xd8:
02802       /* EXternal ref.  */
02803       NEXT ();
02804       OUT (0xf1);
02805       OUT (0xd8);
02806       EXP;
02807       EXP;
02808       EXP;
02809       EXP;
02810       break;
02811     case 0xce:
02812       NEXT ();
02813       OUT (0xf1);
02814       OUT (0xce);
02815       INT;
02816       INT;
02817       ch = THIS ();
02818       INT;
02819       switch (ch)
02820        {
02821        case 0x01:
02822          INT;
02823          INT;
02824          break;
02825        case 0x02:
02826          INT;
02827          break;
02828        case 0x04:
02829          EXPn (external function);
02830          break;
02831        case 0x05:
02832          break;
02833        case 0x07:
02834          INTn (line number);
02835          INT;
02836        case 0x08:
02837          break;
02838        case 0x0a:
02839          INTn (locked register);
02840          INT;
02841          break;
02842        case 0x3f:
02843          copy_till_end ();
02844          break;
02845        case 0x3e:
02846          copy_till_end ();
02847          break;
02848        case 0x40:
02849          copy_till_end ();
02850          break;
02851        case 0x41:
02852          ID;
02853          break;
02854        }
02855     }
02856 }
02857 
02858 static void
02859 f0_record (void)
02860 {
02861   /* Attribute record.  */
02862   NEXT ();
02863   OUT (0xf0);
02864   INTn (Symbol name);
02865   ID;
02866 }
02867 
02868 static void
02869 f2_record (void)
02870 {
02871   NEXT ();
02872   OUT (0xf2);
02873   INT;
02874   NEXT ();
02875   OUT (0xce);
02876   INT;
02877   copy_till_end ();
02878 }
02879 
02880 static void
02881 f8_record (void)
02882 {
02883   int ch;
02884   NEXT ();
02885   ch = THIS ();
02886   switch (ch)
02887     {
02888     case 0x01:
02889     case 0x02:
02890     case 0x03:
02891       /* Unique typedefs for module.  */
02892       /* GLobal typedefs.   */
02893       /* High level module scope beginning.  */
02894       {
02895        struct output_buffer_struct ob;
02896 
02897        NEXT ();
02898        OUT (0xf8);
02899        OUT (ch);
02900        drop_int (&ob);
02901        ID;
02902 
02903        block ();
02904 
02905        NEXT ();
02906        fill_int (&ob);
02907        OUT (0xf9);
02908       }
02909       break;
02910     case 0x04:
02911       /* Global function.  */
02912       {
02913        struct output_buffer_struct ob;
02914 
02915        NEXT ();
02916        OUT (0xf8);
02917        OUT (0x04);
02918        drop_int (&ob);
02919        ID;
02920        INTn (stack size);
02921        INTn (ret val);
02922        EXPn (offset);
02923 
02924        block ();
02925 
02926        NEXT ();
02927        OUT (0xf9);
02928        EXPn (size of block);
02929        fill_int (&ob);
02930       }
02931       break;
02932 
02933     case 0x05:
02934       /* File name for source line numbers.  */
02935       {
02936        struct output_buffer_struct ob;
02937 
02938        NEXT ();
02939        OUT (0xf8);
02940        OUT (0x05);
02941        drop_int (&ob);
02942        ID;
02943        INTn (year);
02944        INTn (month);
02945        INTn (day);
02946        INTn (hour);
02947        INTn (monute);
02948        INTn (second);
02949        block ();
02950        NEXT ();
02951        OUT (0xf9);
02952        fill_int (&ob);
02953       }
02954       break;
02955 
02956     case 0x06:
02957       /* Local function.  */
02958       {
02959        struct output_buffer_struct ob;
02960 
02961        NEXT ();
02962        OUT (0xf8);
02963        OUT (0x06);
02964        drop_int (&ob);
02965        ID;
02966        INTn (stack size);
02967        INTn (type return);
02968        EXPn (offset);
02969        block ();
02970        NEXT ();
02971        OUT (0xf9);
02972        EXPn (size);
02973        fill_int (&ob);
02974       }
02975       break;
02976 
02977     case 0x0a:
02978       /* Assembler module scope beginning -  */
02979       {
02980        struct output_buffer_struct ob;
02981 
02982        NEXT ();
02983        OUT (0xf8);
02984        OUT (0x0a);
02985        drop_int (&ob);
02986        ID;
02987        ID;
02988        INT;
02989        ID;
02990        INT;
02991        INT;
02992        INT;
02993        INT;
02994        INT;
02995        INT;
02996 
02997        block ();
02998 
02999        NEXT ();
03000        OUT (0xf9);
03001        fill_int (&ob);
03002       }
03003       break;
03004     case 0x0b:
03005       {
03006        struct output_buffer_struct ob;
03007 
03008        NEXT ();
03009        OUT (0xf8);
03010        OUT (0x0b);
03011        drop_int (&ob);
03012        ID;
03013        INT;
03014        INTn (section index);
03015        EXPn (offset);
03016        INTn (stuff);
03017 
03018        block ();
03019 
03020        OUT (0xf9);
03021        NEXT ();
03022        EXPn (Size in Maus);
03023        fill_int (&ob);
03024       }
03025       break;
03026     }
03027 }
03028 
03029 static void
03030 e2_record (void)
03031 {
03032   OUT (0xe2);
03033   NEXT ();
03034   OUT (0xce);
03035   NEXT ();
03036   INT;
03037   EXP;
03038 }
03039 
03040 static void
03041 block (void)
03042 {
03043   int ch;
03044 
03045   while (1)
03046     {
03047       ch = THIS ();
03048       switch (ch)
03049        {
03050        case 0xe1:
03051        case 0xe5:
03052          return;
03053        case 0xf9:
03054          return;
03055        case 0xf0:
03056          f0_record ();
03057          break;
03058        case 0xf1:
03059          f1_record ();
03060          break;
03061        case 0xf2:
03062          f2_record ();
03063          break;
03064        case 0xf8:
03065          f8_record ();
03066          break;
03067        case 0xe2:
03068          e2_record ();
03069          break;
03070 
03071        }
03072     }
03073 }
03074 
03075 /* Moves all the debug information from the source bfd to the output
03076    bfd, and relocates any expressions it finds.  */
03077 
03078 static void
03079 relocate_debug (bfd *output ATTRIBUTE_UNUSED,
03080               bfd *input)
03081 {
03082 #define IBS 400
03083 #define OBS 400
03084   unsigned char input_buffer[IBS];
03085 
03086   input_ptr_start = input_ptr = input_buffer;
03087   input_ptr_end = input_buffer + IBS;
03088   input_bfd = input;
03089   /* FIXME: Check return value.  I'm not sure whether it needs to read
03090      the entire buffer or not.  */
03091   bfd_bread ((void *) input_ptr_start, (bfd_size_type) IBS, input);
03092   block ();
03093 }
03094 
03095 /* Gather together all the debug information from each input BFD into
03096    one place, relocating it and emitting it as we go.  */
03097 
03098 static bfd_boolean
03099 ieee_write_debug_part (bfd *abfd)
03100 {
03101   ieee_data_type *ieee = IEEE_DATA (abfd);
03102   bfd_chain_type *chain = ieee->chain_root;
03103   unsigned char obuff[OBS];
03104   bfd_boolean some_debug = FALSE;
03105   file_ptr here = bfd_tell (abfd);
03106 
03107   output_ptr_start = output_ptr = obuff;
03108   output_ptr_end = obuff + OBS;
03109   output_ptr = obuff;
03110   output_bfd = abfd;
03111 
03112   if (chain == (bfd_chain_type *) NULL)
03113     {
03114       asection *s;
03115 
03116       for (s = abfd->sections; s != NULL; s = s->next)
03117        if ((s->flags & SEC_DEBUGGING) != 0)
03118          break;
03119       if (s == NULL)
03120        {
03121          ieee->w.r.debug_information_part = 0;
03122          return TRUE;
03123        }
03124 
03125       ieee->w.r.debug_information_part = here;
03126       if (bfd_bwrite (s->contents, s->size, abfd) != s->size)
03127        return FALSE;
03128     }
03129   else
03130     {
03131       while (chain != (bfd_chain_type *) NULL)
03132        {
03133          bfd *entry = chain->this;
03134          ieee_data_type *entry_ieee = IEEE_DATA (entry);
03135 
03136          if (entry_ieee->w.r.debug_information_part)
03137            {
03138              if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
03139                          SEEK_SET) != 0)
03140               return FALSE;
03141              relocate_debug (abfd, entry);
03142            }
03143 
03144          chain = chain->next;
03145        }
03146 
03147       if (some_debug)
03148        ieee->w.r.debug_information_part = here;
03149       else
03150        ieee->w.r.debug_information_part = 0;
03151 
03152       flush ();
03153     }
03154 
03155   return TRUE;
03156 }
03157 
03158 /* Write the data in an ieee way.  */
03159 
03160 static bfd_boolean
03161 ieee_write_data_part (bfd *abfd)
03162 {
03163   asection *s;
03164 
03165   ieee_data_type *ieee = IEEE_DATA (abfd);
03166   ieee->w.r.data_part = bfd_tell (abfd);
03167 
03168   for (s = abfd->sections; s != (asection *) NULL; s = s->next)
03169     {
03170       /* Skip sections that have no loadable contents (.bss,
03171          debugging, etc.)  */
03172       if ((s->flags & SEC_LOAD) == 0)
03173        continue;
03174 
03175       /* Sort the reloc records so we can insert them in the correct
03176         places.  */
03177       if (s->reloc_count != 0)
03178        {
03179          if (! do_with_relocs (abfd, s))
03180            return FALSE;
03181        }
03182       else
03183        {
03184          if (! do_without_relocs (abfd, s))
03185            return FALSE;
03186        }
03187     }
03188 
03189   return TRUE;
03190 }
03191 
03192 static bfd_boolean
03193 init_for_output (bfd *abfd)
03194 {
03195   asection *s;
03196 
03197   for (s = abfd->sections; s != (asection *) NULL; s = s->next)
03198     {
03199       if ((s->flags & SEC_DEBUGGING) != 0)
03200        continue;
03201       if (s->size != 0)
03202        {
03203          bfd_size_type size = s->size;
03204          ieee_per_section (s)->data = bfd_alloc (abfd, size);
03205          if (!ieee_per_section (s)->data)
03206            return FALSE;
03207        }
03208     }
03209   return TRUE;
03210 }
03211 
03212 /* Exec and core file sections.  */
03213 
03214 /* Set section contents is complicated with IEEE since the format is
03215    not a byte image, but a record stream.  */
03216 
03217 static bfd_boolean
03218 ieee_set_section_contents (bfd *abfd,
03219                         sec_ptr section,
03220                         const void * location,
03221                         file_ptr offset,
03222                         bfd_size_type count)
03223 {
03224   if ((section->flags & SEC_DEBUGGING) != 0)
03225     {
03226       if (section->contents == NULL)
03227        {
03228          bfd_size_type size = section->size;
03229          section->contents = bfd_alloc (abfd, size);
03230          if (section->contents == NULL)
03231            return FALSE;
03232        }
03233       /* bfd_set_section_contents has already checked that everything
03234          is within range.  */
03235       memcpy (section->contents + offset, location, (size_t) count);
03236       return TRUE;
03237     }
03238 
03239   if (ieee_per_section (section)->data == (bfd_byte *) NULL)
03240     {
03241       if (!init_for_output (abfd))
03242        return FALSE;
03243     }
03244   memcpy ((void *) (ieee_per_section (section)->data + offset),
03245          (void *) location,
03246          (unsigned int) count);
03247   return TRUE;
03248 }
03249 
03250 /* Write the external symbols of a file.  IEEE considers two sorts of
03251    external symbols, public, and referenced.  It uses to internal
03252    forms to index them as well.  When we write them out we turn their
03253    symbol values into indexes from the right base.  */
03254 
03255 static bfd_boolean
03256 ieee_write_external_part (bfd *abfd)
03257 {
03258   asymbol **q;
03259   ieee_data_type *ieee = IEEE_DATA (abfd);
03260   unsigned int reference_index = IEEE_REFERENCE_BASE;
03261   unsigned int public_index = IEEE_PUBLIC_BASE + 2;
03262   file_ptr here = bfd_tell (abfd);
03263   bfd_boolean hadone = FALSE;
03264 
03265   if (abfd->outsymbols != (asymbol **) NULL)
03266     {
03267 
03268       for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
03269        {
03270          asymbol *p = *q;
03271 
03272          if (bfd_is_und_section (p->section))
03273            {
03274              /* This must be a symbol reference.  */
03275              if (! ieee_write_byte (abfd, ieee_external_reference_enum)
03276                 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
03277                 || ! ieee_write_id (abfd, p->name))
03278               return FALSE;
03279              p->value = reference_index;
03280              reference_index++;
03281              hadone = TRUE;
03282            }
03283          else if (bfd_is_com_section (p->section))
03284            {
03285              /* This is a weak reference.  */
03286              if (! ieee_write_byte (abfd, ieee_external_reference_enum)
03287                 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
03288                 || ! ieee_write_id (abfd, p->name)
03289                 || ! ieee_write_byte (abfd,
03290                                    ieee_weak_external_reference_enum)
03291                 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
03292                 || ! ieee_write_int (abfd, p->value))
03293               return FALSE;
03294              p->value = reference_index;
03295              reference_index++;
03296              hadone = TRUE;
03297            }
03298          else if (p->flags & BSF_GLOBAL)
03299            {
03300              /* This must be a symbol definition.  */
03301              if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
03302                 || ! ieee_write_int (abfd, (bfd_vma) public_index)
03303                 || ! ieee_write_id (abfd, p->name)
03304                 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
03305                 || ! ieee_write_int (abfd, (bfd_vma) public_index)
03306                 || ! ieee_write_byte (abfd, 15) /* Instruction address.  */
03307                 || ! ieee_write_byte (abfd, 19) /* Static symbol.  */
03308                 || ! ieee_write_byte (abfd, 1)) /* One of them.  */
03309               return FALSE;
03310 
03311              /* Write out the value.  */
03312              if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
03313                 || ! ieee_write_int (abfd, (bfd_vma) public_index))
03314               return FALSE;
03315              if (! bfd_is_abs_section (p->section))
03316               {
03317                 if (abfd->flags & EXEC_P)
03318                   {
03319                     /* If fully linked, then output all symbols
03320                       relocated.  */
03321                     if (! (ieee_write_int
03322                           (abfd,
03323                            (p->value
03324                             + p->section->output_offset
03325                             + p->section->output_section->vma))))
03326                      return FALSE;
03327                   }
03328                 else
03329                   {
03330                     if (! (ieee_write_expression
03331                           (abfd,
03332                            p->value + p->section->output_offset,
03333                            p->section->output_section->symbol,
03334                            FALSE, 0)))
03335                      return FALSE;
03336                   }
03337               }
03338              else
03339               {
03340                 if (! ieee_write_expression (abfd,
03341                                           p->value,
03342                                           bfd_abs_section_ptr->symbol,
03343                                           FALSE, 0))
03344                   return FALSE;
03345               }
03346              p->value = public_index;
03347              public_index++;
03348              hadone = TRUE;
03349            }
03350          else
03351            {
03352              /* This can happen - when there are gaps in the symbols read
03353                 from an input ieee file.  */
03354            }
03355        }
03356     }
03357   if (hadone)
03358     ieee->w.r.external_part = here;
03359 
03360   return TRUE;
03361 }
03362 
03363 
03364 static const unsigned char exten[] =
03365 {
03366   0xf0, 0x20, 0x00,
03367   0xf1, 0xce, 0x20, 0x00, 37, 3, 3,       /* Set version 3 rev 3.  */
03368   0xf1, 0xce, 0x20, 0x00, 39, 2,   /* Keep symbol in  original case.  */
03369   0xf1, 0xce, 0x20, 0x00, 38              /* Set object type relocatable to x.  */
03370 };
03371 
03372 static const unsigned char envi[] =
03373 {
03374   0xf0, 0x21, 0x00,
03375 
03376 /*    0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
03377     0x19, 0x2c,
03378 */
03379   0xf1, 0xce, 0x21, 00, 52, 0x00,  /* exec ok.  */
03380 
03381   0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix.  */
03382 /*    0xf1, 0xce, 0x21, 0, 54, 2,1,1      tool & version # */
03383 };
03384 
03385 static bfd_boolean
03386 ieee_write_me_part (bfd *abfd)
03387 {
03388   ieee_data_type *ieee = IEEE_DATA (abfd);
03389   ieee->w.r.trailer_part = bfd_tell (abfd);
03390   if (abfd->start_address)
03391     {
03392       if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
03393          || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
03394          || ! ieee_write_int (abfd, abfd->start_address)
03395          || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
03396        return FALSE;
03397     }
03398   ieee->w.r.me_record = bfd_tell (abfd);
03399   if (! ieee_write_byte (abfd, ieee_module_end_enum))
03400     return FALSE;
03401   return TRUE;
03402 }
03403 
03404 /* Write out the IEEE processor ID.  */
03405 
03406 static bfd_boolean
03407 ieee_write_processor (bfd *abfd)
03408 {
03409   const bfd_arch_info_type *arch;
03410 
03411   arch = bfd_get_arch_info (abfd);
03412   switch (arch->arch)
03413     {
03414     default:
03415       if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
03416        return FALSE;
03417       break;
03418 
03419     case bfd_arch_h8300:
03420       if (! ieee_write_id (abfd, "H8/300"))
03421        return FALSE;
03422       break;
03423 
03424     case bfd_arch_h8500:
03425       if (! ieee_write_id (abfd, "H8/500"))
03426        return FALSE;
03427       break;
03428 
03429     case bfd_arch_i960:
03430       switch (arch->mach)
03431        {
03432        default:
03433        case bfd_mach_i960_core:
03434        case bfd_mach_i960_ka_sa:
03435          if (! ieee_write_id (abfd, "80960KA"))
03436            return FALSE;
03437          break;
03438 
03439        case bfd_mach_i960_kb_sb:
03440          if (! ieee_write_id (abfd, "80960KB"))
03441            return FALSE;
03442          break;
03443 
03444        case bfd_mach_i960_ca:
03445          if (! ieee_write_id (abfd, "80960CA"))
03446            return FALSE;
03447          break;
03448 
03449        case bfd_mach_i960_mc:
03450        case bfd_mach_i960_xa:
03451          if (! ieee_write_id (abfd, "80960MC"))
03452            return FALSE;
03453          break;
03454        }
03455       break;
03456 
03457     case bfd_arch_m68k:
03458       {
03459        const char *id;
03460 
03461        switch (arch->mach)
03462          {
03463          default:           id = "68020"; break;
03464          case bfd_mach_m68000: id = "68000"; break;
03465          case bfd_mach_m68008: id = "68008"; break;
03466          case bfd_mach_m68010: id = "68010"; break;
03467          case bfd_mach_m68020: id = "68020"; break;
03468          case bfd_mach_m68030: id = "68030"; break;
03469          case bfd_mach_m68040: id = "68040"; break;
03470          case bfd_mach_m68060: id = "68060"; break;
03471          case bfd_mach_cpu32:  id = "cpu32"; break;
03472          case bfd_mach_mcf_isa_a_nodiv: id = "isa-a:nodiv"; break;
03473          case bfd_mach_mcf_isa_a: id = "isa-a"; break;
03474          case bfd_mach_mcf_isa_a_mac: id = "isa-a:mac"; break;
03475          case bfd_mach_mcf_isa_a_emac: id = "isa-a:emac"; break;
03476          case bfd_mach_mcf_isa_aplus: id = "isa-aplus"; break;
03477          case bfd_mach_mcf_isa_aplus_mac: id = "isa-aplus:mac"; break;
03478          case bfd_mach_mcf_isa_aplus_emac: id = "isa-aplus:mac"; break;
03479          case bfd_mach_mcf_isa_b_nousp: id = "isa-b:nousp"; break;
03480          case bfd_mach_mcf_isa_b_nousp_mac: id = "isa-b:nousp:mac"; break;
03481          case bfd_mach_mcf_isa_b_nousp_emac: id = "isa-b:nousp:emac"; break;
03482          case bfd_mach_mcf_isa_b: id = "isa-b"; break;
03483          case bfd_mach_mcf_isa_b_mac: id = "isa-b:mac"; break;
03484          case bfd_mach_mcf_isa_b_emac: id = "isa-b:emac"; break;
03485          case bfd_mach_mcf_isa_b_float: id = "isa-b:float"; break;
03486          case bfd_mach_mcf_isa_b_float_mac: id = "isa-b:float:mac"; break;
03487          case bfd_mach_mcf_isa_b_float_emac: id = "isa-b:float:emac"; break;
03488          }
03489 
03490        if (! ieee_write_id (abfd, id))
03491          return FALSE;
03492       }
03493       break;
03494     }
03495 
03496   return TRUE;
03497 }
03498 
03499 static bfd_boolean
03500 ieee_write_object_contents (bfd *abfd)
03501 {
03502   ieee_data_type *ieee = IEEE_DATA (abfd);
03503   unsigned int i;
03504   file_ptr old;
03505 
03506   /* Fast forward over the header area.  */
03507   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
03508     return FALSE;
03509 
03510   if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
03511       || ! ieee_write_processor (abfd)
03512       || ! ieee_write_id (abfd, abfd->filename))
03513     return FALSE;
03514 
03515   /* Fast forward over the variable bits.  */
03516   if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
03517     return FALSE;
03518 
03519   /* Bits per MAU.  */
03520   if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
03521     return FALSE;
03522   /* MAU's per address.  */
03523   if (! ieee_write_byte (abfd,
03524                       (bfd_byte) (bfd_arch_bits_per_address (abfd)
03525                                  / bfd_arch_bits_per_byte (abfd))))
03526     return FALSE;
03527 
03528   old = bfd_tell (abfd);
03529   if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
03530     return FALSE;
03531 
03532   ieee->w.r.extension_record = bfd_tell (abfd);
03533   if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
03534       != sizeof (exten))
03535     return FALSE;
03536   if (abfd->flags & EXEC_P)
03537     {
03538       if (! ieee_write_byte (abfd, 0x1)) /* Absolute.  */
03539        return FALSE;
03540     }
03541   else
03542     {
03543       if (! ieee_write_byte (abfd, 0x2)) /* Relocateable.  */
03544        return FALSE;
03545     }
03546 
03547   ieee->w.r.environmental_record = bfd_tell (abfd);
03548   if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
03549       != sizeof (envi))
03550     return FALSE;
03551 
03552   /* The HP emulator database requires a timestamp in the file.  */
03553   {
03554     time_t now;
03555     const struct tm *t;
03556 
03557     time (&now);
03558     t = (struct tm *) localtime (&now);
03559     if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
03560        || ! ieee_write_byte (abfd, 0x21)
03561        || ! ieee_write_byte (abfd, 0)
03562        || ! ieee_write_byte (abfd, 50)
03563        || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
03564        || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
03565        || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
03566        || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
03567        || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
03568        || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
03569       return FALSE;
03570   }
03571 
03572   output_bfd = abfd;
03573 
03574   flush ();
03575 
03576   if (! ieee_write_section_part (abfd))
03577     return FALSE;
03578   /* First write the symbols.  This changes their values into table
03579     indeces so we cant use it after this point.  */
03580   if (! ieee_write_external_part (abfd))
03581     return FALSE;
03582 
03583   /* Write any debugs we have been told about.  */
03584   if (! ieee_write_debug_part (abfd))
03585     return FALSE;
03586 
03587   /* Can only write the data once the symbols have been written, since
03588      the data contains relocation information which points to the
03589      symbols.  */
03590   if (! ieee_write_data_part (abfd))
03591     return FALSE;
03592 
03593   /* At the end we put the end!  */
03594   if (! ieee_write_me_part (abfd))
03595     return FALSE;
03596 
03597   /* Generate the header.  */
03598   if (bfd_seek (abfd, old, SEEK_SET) != 0)
03599     return FALSE;
03600 
03601   for (i = 0; i < N_W_VARIABLES; i++)
03602     {
03603       if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
03604          || ! ieee_write_byte (abfd, (bfd_byte) i)
03605          || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
03606        return FALSE;
03607     }
03608 
03609   return TRUE;
03610 }
03611 
03612 /* Native-level interface to symbols.  */
03613 
03614 /* We read the symbols into a buffer, which is discarded when this
03615    function exits.  We read the strings into a buffer large enough to
03616    hold them all plus all the cached symbol entries.  */
03617 
03618 static asymbol *
03619 ieee_make_empty_symbol (bfd *abfd)
03620 {
03621   bfd_size_type amt = sizeof (ieee_symbol_type);
03622   ieee_symbol_type *new = bfd_zalloc (abfd, amt);
03623 
03624   if (!new)
03625     return NULL;
03626   new->symbol.the_bfd = abfd;
03627   return &new->symbol;
03628 }
03629 
03630 static bfd *
03631 ieee_openr_next_archived_file (bfd *arch, bfd *prev)
03632 {
03633   ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
03634 
03635   /* Take the next one from the arch state, or reset.  */
03636   if (prev == (bfd *) NULL)
03637     /* Reset the index - the first two entries are bogus.  */
03638     ar->element_index = 2;
03639 
03640   while (TRUE)
03641     {
03642       ieee_ar_obstack_type *p = ar->elements + ar->element_index;
03643 
03644       ar->element_index++;
03645       if (ar->element_index <= ar->element_count)
03646        {
03647          if (p->file_offset != (file_ptr) 0)
03648            {
03649              if (p->abfd == (bfd *) NULL)
03650               {
03651                 p->abfd = _bfd_create_empty_archive_element_shell (arch);
03652                 p->abfd->origin = p->file_offset;
03653               }
03654              return p->abfd;
03655            }
03656        }
03657       else
03658        {
03659          bfd_set_error (bfd_error_no_more_archived_files);
03660          return NULL;
03661        }
03662     }
03663 }
03664 
03665 static bfd_boolean
03666 ieee_find_nearest_line (bfd *abfd ATTRIBUTE_UNUSED,
03667                      asection *section ATTRIBUTE_UNUSED,
03668                      asymbol **symbols ATTRIBUTE_UNUSED,
03669                      bfd_vma offset ATTRIBUTE_UNUSED,
03670                      const char **filename_ptr ATTRIBUTE_UNUSED,
03671                      const char **functionname_ptr ATTRIBUTE_UNUSED,
03672                      unsigned int *line_ptr ATTRIBUTE_UNUSED)
03673 {
03674   return FALSE;
03675 }
03676 
03677 static bfd_boolean
03678 ieee_find_inliner_info (bfd *abfd ATTRIBUTE_UNUSED,
03679                      const char **filename_ptr ATTRIBUTE_UNUSED,
03680                      const char **functionname_ptr ATTRIBUTE_UNUSED,
03681                      unsigned int *line_ptr ATTRIBUTE_UNUSED)
03682 {
03683   return FALSE;
03684 }
03685 
03686 static int
03687 ieee_generic_stat_arch_elt (bfd *abfd, struct stat *buf)
03688 {
03689   ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
03690   ieee_data_type *ieee;
03691 
03692   if (abfd->my_archive != NULL)
03693     ar = abfd->my_archive->tdata.ieee_ar_data;
03694   if (ar == (ieee_ar_data_type *) NULL)
03695     {
03696       bfd_set_error (bfd_error_invalid_operation);
03697       return -1;
03698     }
03699 
03700   if (IEEE_DATA (abfd) == NULL)
03701     {
03702       if (ieee_object_p (abfd) == NULL)
03703        {
03704          bfd_set_error (bfd_error_wrong_format);
03705          return -1;
03706        }
03707     }
03708 
03709   ieee = IEEE_DATA (abfd);
03710 
03711   buf->st_size = ieee->w.r.me_record + 1;
03712   buf->st_mode = 0644;
03713   return 0;
03714 }
03715 
03716 static int
03717 ieee_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
03718                    struct bfd_link_info *info ATTRIBUTE_UNUSED)
03719 {
03720   return 0;
03721 }
03722 
03723 #define       ieee_close_and_cleanup _bfd_generic_close_and_cleanup
03724 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
03725 
03726 #define ieee_slurp_armap bfd_true
03727 #define ieee_slurp_extended_name_table bfd_true
03728 #define ieee_construct_extended_name_table \
03729   ((bfd_boolean (*) \
03730     (bfd *, char **, bfd_size_type *, const char **)) \
03731    bfd_true)
03732 #define ieee_truncate_arname bfd_dont_truncate_arname
03733 #define ieee_write_armap \
03734   ((bfd_boolean (*) \
03735     (bfd *, unsigned int, struct orl *, unsigned int, int)) \
03736    bfd_true)
03737 #define ieee_read_ar_hdr bfd_nullvoidptr
03738 #define ieee_update_armap_timestamp bfd_true
03739 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
03740 
03741 #define ieee_bfd_is_target_special_symbol  \
03742   ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
03743 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
03744 #define ieee_get_lineno _bfd_nosymbols_get_lineno
03745 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
03746 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
03747 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
03748 
03749 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
03750 #define ieee_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
03751 
03752 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
03753 
03754 #define ieee_get_section_contents_in_window \
03755   _bfd_generic_get_section_contents_in_window
03756 #define ieee_bfd_get_relocated_section_contents \
03757   bfd_generic_get_relocated_section_contents
03758 #define ieee_bfd_relax_section bfd_generic_relax_section
03759 #define ieee_bfd_gc_sections bfd_generic_gc_sections
03760 #define ieee_bfd_merge_sections bfd_generic_merge_sections
03761 #define ieee_bfd_is_group_section bfd_generic_is_group_section
03762 #define ieee_bfd_discard_group bfd_generic_discard_group
03763 #define ieee_section_already_linked \
03764   _bfd_generic_section_already_linked
03765 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
03766 #define ieee_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
03767 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
03768 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
03769 #define ieee_bfd_final_link _bfd_generic_final_link
03770 #define ieee_bfd_link_split_section  _bfd_generic_link_split_section
03771 
03772 const bfd_target ieee_vec =
03773 {
03774   "ieee",                   /* Name.  */
03775   bfd_target_ieee_flavour,
03776   BFD_ENDIAN_UNKNOWN,              /* Target byte order.  */
03777   BFD_ENDIAN_UNKNOWN,              /* Target headers byte order.  */
03778   (HAS_RELOC | EXEC_P |            /* Object flags.  */
03779    HAS_LINENO | HAS_DEBUG |
03780    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
03781   (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
03782    | SEC_ALLOC | SEC_LOAD | SEC_RELOC),   /* Section flags.  */
03783   '_',                      /* Leading underscore.  */
03784   ' ',                      /* AR_pad_char.  */
03785   16,                       /* AR_max_namelen.  */
03786   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
03787   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
03788   bfd_getb16, bfd_getb_signed_16, bfd_putb16,    /* Data.  */
03789   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
03790   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
03791   bfd_getb16, bfd_getb_signed_16, bfd_putb16,    /* Headers.  */
03792 
03793   {_bfd_dummy_target,
03794    ieee_object_p,           /* bfd_check_format.  */
03795    ieee_archive_p,
03796    _bfd_dummy_target,
03797   },
03798   {
03799     bfd_false,
03800     ieee_mkobject,
03801     _bfd_generic_mkarchive,
03802     bfd_false
03803   },
03804   {
03805     bfd_false,
03806     ieee_write_object_contents,
03807     _bfd_write_archive_contents,
03808     bfd_false,
03809   },
03810 
03811   /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
03812      ieee_get_section_contents, ieee_get_section_contents_in_window.  */
03813   BFD_JUMP_TABLE_GENERIC (ieee),
03814 
03815   BFD_JUMP_TABLE_COPY (_bfd_generic),
03816   BFD_JUMP_TABLE_CORE (_bfd_nocore),
03817 
03818   /* ieee_slurp_armap, ieee_slurp_extended_name_table,
03819      ieee_construct_extended_name_table, ieee_truncate_arname,
03820      ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
03821      ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
03822      ieee_update_armap_timestamp.  */
03823   BFD_JUMP_TABLE_ARCHIVE (ieee),
03824 
03825   /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
03826      ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
03827      ieee_bfd_is_local_label_name, ieee_get_lineno,
03828      ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
03829      ieee_read_minisymbols, ieee_minisymbol_to_symbol.  */
03830   BFD_JUMP_TABLE_SYMBOLS (ieee),
03831 
03832   /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
03833      ieee_bfd_reloc_type_lookup.   */
03834   BFD_JUMP_TABLE_RELOCS (ieee),
03835 
03836   /* ieee_set_arch_mach, ieee_set_section_contents.  */
03837   BFD_JUMP_TABLE_WRITE (ieee),
03838 
03839   /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
03840      ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
03841      _bfd_generic_link_hash_table_free,
03842      ieee_bfd_link_add_symbols, ieee_bfd_final_link,
03843      ieee_bfd_link_split_section, ieee_bfd_gc_sections,
03844      ieee_bfd_merge_sections.  */
03845   BFD_JUMP_TABLE_LINK (ieee),
03846 
03847   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
03848 
03849   NULL,
03850 
03851   NULL
03852 };