Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* ECOFF debugging support.
  2.    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
  3.    2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
  4.    Free Software Foundation, Inc.
  5.    Contributed by Cygnus Support.
  6.    This file was put together by Ian Lance Taylor <ian@cygnus.com>.  A
  7.    good deal of it comes directly from mips-tfile.c, by Michael
  8.    Meissner <meissner@osf.org>.
  9.  
  10.    This file is part of GAS.
  11.  
  12.    GAS is free software; you can redistribute it and/or modify
  13.    it under the terms of the GNU General Public License as published by
  14.    the Free Software Foundation; either version 3, or (at your option)
  15.    any later version.
  16.  
  17.    GAS is distributed in the hope that it will be useful,
  18.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.    GNU General Public License for more details.
  21.  
  22.    You should have received a copy of the GNU General Public License
  23.    along with GAS; see the file COPYING.  If not, write to the Free
  24.    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  25.    02110-1301, USA.  */
  26.  
  27. #include "as.h"
  28.  
  29. /* This file is compiled conditionally for those targets which use
  30.    ECOFF debugging information (e.g., MIPS ELF, Alpha ECOFF).  */
  31.  
  32. #include "ecoff.h"
  33.  
  34. #ifdef ECOFF_DEBUGGING
  35.  
  36. #include "coff/internal.h"
  37. #include "coff/symconst.h"
  38. #include "aout/stab_gnu.h"
  39. #include "filenames.h"
  40. #include "safe-ctype.h"
  41.  
  42. /* Why isn't this in coff/sym.h?  */
  43. #define ST_RFDESCAPE 0xfff
  44.  
  45. /* This file constructs the information used by the ECOFF debugging
  46.    format.  It just builds a large block of data.
  47.  
  48.    We support both ECOFF style debugging and stabs debugging (the
  49.    stabs symbols are encapsulated in ECOFF symbols).  This should let
  50.    us handle anything the compiler might throw at us.  */
  51.  
  52. /* Here is a brief description of the MIPS ECOFF symbol table, by
  53.    Michael Meissner.  The MIPS symbol table has the following pieces:
  54.  
  55.         Symbolic Header
  56.             |
  57.             +-- Auxiliary Symbols
  58.             |
  59.             +-- Dense number table
  60.             |
  61.             +-- Optimizer Symbols
  62.             |
  63.             +-- External Strings
  64.             |
  65.             +-- External Symbols
  66.             |
  67.             +-- Relative file descriptors
  68.             |
  69.             +-- File table
  70.                     |
  71.                     +-- Procedure table
  72.                     |
  73.                     +-- Line number table
  74.                     |
  75.                     +-- Local Strings
  76.                     |
  77.                     +-- Local Symbols
  78.  
  79.    The symbolic header points to each of the other tables, and also
  80.    contains the number of entries.  It also contains a magic number
  81.    and MIPS compiler version number, such as 2.0.
  82.  
  83.    The auxiliary table is a series of 32 bit integers, that are
  84.    referenced as needed from the local symbol table.  Unlike standard
  85.    COFF, the aux.  information does not follow the symbol that uses
  86.    it, but rather is a separate table.  In theory, this would allow
  87.    the MIPS compilers to collapse duplicate aux. entries, but I've not
  88.    noticed this happening with the 1.31 compiler suite.  The different
  89.    types of aux. entries are:
  90.  
  91.     1)  dnLow: Low bound on array dimension.
  92.  
  93.     2)  dnHigh: High bound on array dimension.
  94.  
  95.     3)  isym: Index to the local symbol which is the start of the
  96.         function for the end of function first aux. entry.
  97.  
  98.     4)  width: Width of structures and bitfields.
  99.  
  100.     5)  count: Count of ranges for variant part.
  101.  
  102.     6)  rndx: A relative index into the symbol table.  The relative
  103.         index field has two parts: rfd which is a pointer into the
  104.         relative file index table or ST_RFDESCAPE which says the next
  105.         aux. entry is the file number, and index: which is the pointer
  106.         into the local symbol within a given file table.  This is for
  107.         things like references to types defined in another file.
  108.  
  109.     7)  Type information: This is like the COFF type bits, except it
  110.         is 32 bits instead of 16; they still have room to add new
  111.         basic types; and they can handle more than 6 levels of array,
  112.         pointer, function, etc.  Each type information field contains
  113.         the following structure members:
  114.  
  115.             a)  fBitfield: a bit that says this is a bitfield, and the
  116.                 size in bits follows as the next aux. entry.
  117.  
  118.             b)  continued: a bit that says the next aux. entry is a
  119.                 continuation of the current type information (in case
  120.                 there are more than 6 levels of array/ptr/function).
  121.  
  122.             c)  bt: an integer containing the base type before adding
  123.                 array, pointer, function, etc. qualifiers.  The
  124.                 current base types that I have documentation for are:
  125.  
  126.                         btNil           -- undefined
  127.                         btAdr           -- address - integer same size as ptr
  128.                         btChar          -- character
  129.                         btUChar         -- unsigned character
  130.                         btShort         -- short
  131.                         btUShort        -- unsigned short
  132.                         btInt           -- int
  133.                         btUInt          -- unsigned int
  134.                         btLong          -- long
  135.                         btULong         -- unsigned long
  136.                         btFloat         -- float (real)
  137.                         btDouble        -- Double (real)
  138.                         btStruct        -- Structure (Record)
  139.                         btUnion         -- Union (variant)
  140.                         btEnum          -- Enumerated
  141.                         btTypedef       -- defined via a typedef isymRef
  142.                         btRange         -- subrange of int
  143.                         btSet           -- pascal sets
  144.                         btComplex       -- fortran complex
  145.                         btDComplex      -- fortran double complex
  146.                         btIndirect      -- forward or unnamed typedef
  147.                         btFixedDec      -- Fixed Decimal
  148.                         btFloatDec      -- Float Decimal
  149.                         btString        -- Varying Length Character String
  150.                         btBit           -- Aligned Bit String
  151.                         btPicture       -- Picture
  152.                         btVoid          -- Void (MIPS cc revision >= 2.00)
  153.  
  154.             d)  tq0 - tq5: type qualifier fields as needed.  The
  155.                 current type qualifier fields I have documentation for
  156.                 are:
  157.  
  158.                         tqNil           -- no more qualifiers
  159.                         tqPtr           -- pointer
  160.                         tqProc          -- procedure
  161.                         tqArray         -- array
  162.                         tqFar           -- 8086 far pointers
  163.                         tqVol           -- volatile
  164.  
  165.    The dense number table is used in the front ends, and disappears by
  166.    the time the .o is created.
  167.  
  168.    With the 1.31 compiler suite, the optimization symbols don't seem
  169.    to be used as far as I can tell.
  170.  
  171.    The linker is the first entity that creates the relative file
  172.    descriptor table, and I believe it is used so that the individual
  173.    file table pointers don't have to be rewritten when the objects are
  174.    merged together into the program file.
  175.  
  176.    Unlike COFF, the basic symbol & string tables are split into
  177.    external and local symbols/strings.  The relocation information
  178.    only goes off of the external symbol table, and the debug
  179.    information only goes off of the internal symbol table.  The
  180.    external symbols can have links to an appropriate file index and
  181.    symbol within the file to give it the appropriate type information.
  182.    Because of this, the external symbols are actually larger than the
  183.    internal symbols (to contain the link information), and contain the
  184.    local symbol structure as a member, though this member is not the
  185.    first member of the external symbol structure (!).  I suspect this
  186.    split is to make strip easier to deal with.
  187.  
  188.    Each file table has offsets for where the line numbers, local
  189.    strings, local symbols, and procedure table starts from within the
  190.    global tables, and the indexs are reset to 0 for each of those
  191.    tables for the file.
  192.  
  193.    The procedure table contains the binary equivalents of the .ent
  194.    (start of the function address), .frame (what register is the
  195.    virtual frame pointer, constant offset from the register to obtain
  196.    the VFP, and what register holds the return address), .mask/.fmask
  197.    (bitmask of saved registers, and where the first register is stored
  198.    relative to the VFP) assembler directives.  It also contains the
  199.    low and high bounds of the line numbers if debugging is turned on.
  200.  
  201.    The line number table is a compressed form of the normal COFF line
  202.    table.  Each line number entry is either 1 or 3 bytes long, and
  203.    contains a signed delta from the previous line, and an unsigned
  204.    count of the number of instructions this statement takes.
  205.  
  206.    The local symbol table contains the following fields:
  207.  
  208.     1)  iss: index to the local string table giving the name of the
  209.         symbol.
  210.  
  211.     2)  value: value of the symbol (address, register number, etc.).
  212.  
  213.     3)  st: symbol type.  The current symbol types are:
  214.  
  215.             stNil         -- Nuthin' special
  216.             stGlobal      -- external symbol
  217.             stStatic      -- static
  218.             stParam       -- procedure argument
  219.             stLocal       -- local variable
  220.             stLabel       -- label
  221.             stProc        -- External Procedure
  222.             stBlock       -- beginning of block
  223.             stEnd         -- end (of anything)
  224.             stMember      -- member (of anything)
  225.             stTypedef     -- type definition
  226.             stFile        -- file name
  227.             stRegReloc    -- register relocation
  228.             stForward     -- forwarding address
  229.             stStaticProc  -- Static procedure
  230.             stConstant    -- const
  231.  
  232.     4)  sc: storage class.  The current storage classes are:
  233.  
  234.             scText        -- text symbol
  235.             scData        -- initialized data symbol
  236.             scBss         -- un-initialized data symbol
  237.             scRegister    -- value of symbol is register number
  238.             scAbs         -- value of symbol is absolute
  239.             scUndefined   -- who knows?
  240.             scCdbLocal    -- variable's value is IN se->va.??
  241.             scBits        -- this is a bit field
  242.             scCdbSystem   -- value is IN debugger's address space
  243.             scRegImage    -- register value saved on stack
  244.             scInfo        -- symbol contains debugger information
  245.             scUserStruct  -- addr in struct user for current process
  246.             scSData       -- load time only small data
  247.             scSBss        -- load time only small common
  248.             scRData       -- load time only read only data
  249.             scVar         -- Var parameter (fortranpascal)
  250.             scCommon      -- common variable
  251.             scSCommon     -- small common
  252.             scVarRegister -- Var parameter in a register
  253.             scVariant     -- Variant record
  254.             scSUndefined  -- small undefined(external) data
  255.             scInit        -- .init section symbol
  256.  
  257.     5)  index: pointer to a local symbol or aux. entry.
  258.  
  259.    For the following program:
  260.  
  261.         #include <stdio.h>
  262.  
  263.         main(){
  264.                 printf("Hello World!\n");
  265.                 return 0;
  266.         }
  267.  
  268.    Mips-tdump produces the following information:
  269.  
  270.    Global file header:
  271.        magic number             0x162
  272.        # sections               2
  273.        timestamp                645311799, Wed Jun 13 17:16:39 1990
  274.        symbolic header offset   284
  275.        symbolic header size     96
  276.        optional header          56
  277.        flags                    0x0
  278.  
  279.    Symbolic header, magic number = 0x7009, vstamp = 1.31:
  280.  
  281.        Info                      Offset      Number       Bytes
  282.        ====                      ======      ======      =====
  283.  
  284.        Line numbers                 380           4           4 [13]
  285.        Dense numbers                  0           0           0
  286.        Procedures Tables            384           1          52
  287.        Local Symbols                436          16         192
  288.        Optimization Symbols           0           0           0
  289.        Auxiliary Symbols            628          39         156
  290.        Local Strings                784          80          80
  291.        External Strings             864         144         144
  292.        File Tables                 1008           2         144
  293.        Relative Files                 0           0           0
  294.        External Symbols            1152          20         320
  295.  
  296.    File #0, "hello2.c"
  297.  
  298.        Name index  = 1          Readin      = No
  299.        Merge       = No         Endian      = LITTLE
  300.        Debug level = G2         Language    = C
  301.        Adr         = 0x00000000
  302.  
  303.        Info                       Start      Number        Size      Offset
  304.        ====                       =====      ======        ====      ======
  305.        Local strings                  0          15          15         784
  306.        Local symbols                  0           6          72         436
  307.        Line numbers                   0          13          13         380
  308.        Optimization symbols           0           0           0           0
  309.        Procedures                     0           1          52         384
  310.        Auxiliary symbols              0          14          56         628
  311.        Relative Files                 0           0           0           0
  312.  
  313.     There are 6 local symbols, starting at 436
  314.  
  315.         Symbol# 0: "hello2.c"
  316.             End+1 symbol  = 6
  317.             String index  = 1
  318.             Storage class = Text        Index  = 6
  319.             Symbol type   = File        Value  = 0
  320.  
  321.         Symbol# 1: "main"
  322.             End+1 symbol  = 5
  323.             Type          = int
  324.             String index  = 10
  325.             Storage class = Text        Index  = 12
  326.             Symbol type   = Proc        Value  = 0
  327.  
  328.         Symbol# 2: ""
  329.             End+1 symbol  = 4
  330.             String index  = 0
  331.             Storage class = Text        Index  = 4
  332.             Symbol type   = Block       Value  = 8
  333.  
  334.         Symbol# 3: ""
  335.             First symbol  = 2
  336.             String index  = 0
  337.             Storage class = Text        Index  = 2
  338.             Symbol type   = End         Value  = 28
  339.  
  340.         Symbol# 4: "main"
  341.             First symbol  = 1
  342.             String index  = 10
  343.             Storage class = Text        Index  = 1
  344.             Symbol type   = End         Value  = 52
  345.  
  346.         Symbol# 5: "hello2.c"
  347.             First symbol  = 0
  348.             String index  = 1
  349.             Storage class = Text        Index  = 0
  350.             Symbol type   = End         Value  = 0
  351.  
  352.     There are 14 auxiliary table entries, starting at 628.
  353.  
  354.         * #0               0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  355.         * #1              24, [  24/      0], [ 6 0:0 0:0:0:0:0:0]
  356.         * #2               8, [   8/      0], [ 2 0:0 0:0:0:0:0:0]
  357.         * #3              16, [  16/      0], [ 4 0:0 0:0:0:0:0:0]
  358.         * #4              24, [  24/      0], [ 6 0:0 0:0:0:0:0:0]
  359.         * #5              32, [  32/      0], [ 8 0:0 0:0:0:0:0:0]
  360.         * #6              40, [  40/      0], [10 0:0 0:0:0:0:0:0]
  361.         * #7              44, [  44/      0], [11 0:0 0:0:0:0:0:0]
  362.         * #8              12, [  12/      0], [ 3 0:0 0:0:0:0:0:0]
  363.         * #9              20, [  20/      0], [ 5 0:0 0:0:0:0:0:0]
  364.         * #10             28, [  28/      0], [ 7 0:0 0:0:0:0:0:0]
  365.         * #11             36, [  36/      0], [ 9 0:0 0:0:0:0:0:0]
  366.           #12              5, [   5/      0], [ 1 1:0 0:0:0:0:0:0]
  367.           #13             24, [  24/      0], [ 6 0:0 0:0:0:0:0:0]
  368.  
  369.     There are 1 procedure descriptor entries, starting at 0.
  370.  
  371.         Procedure descriptor 0:
  372.             Name index   = 10          Name          = "main"
  373.             .mask 0x80000000,-4        .fmask 0x00000000,0
  374.             .frame $29,24,$31
  375.             Opt. start   = -1          Symbols start = 1
  376.             First line # = 3           Last line #   = 6
  377.             Line Offset  = 0           Address       = 0x00000000
  378.  
  379.         There are 4 bytes holding line numbers, starting at 380.
  380.             Line           3,   delta     0,   count  2
  381.             Line           4,   delta     1,   count  3
  382.             Line           5,   delta     1,   count  2
  383.             Line           6,   delta     1,   count  6
  384.  
  385.    File #1, "/usr/include/stdio.h"
  386.  
  387.     Name index  = 1          Readin      = No
  388.     Merge       = Yes        Endian      = LITTLE
  389.     Debug level = G2         Language    = C
  390.     Adr         = 0x00000000
  391.  
  392.     Info                       Start      Number        Size      Offset
  393.     ====                       =====      ======        ====      ======
  394.     Local strings                 15          65          65         799
  395.     Local symbols                  6          10         120         508
  396.     Line numbers                   0           0           0         380
  397.     Optimization symbols           0           0           0           0
  398.     Procedures                     1           0           0         436
  399.     Auxiliary symbols             14          25         100         684
  400.     Relative Files                 0           0           0           0
  401.  
  402.     There are 10 local symbols, starting at 442
  403.  
  404.         Symbol# 0: "/usr/include/stdio.h"
  405.             End+1 symbol  = 10
  406.             String index  = 1
  407.             Storage class = Text        Index  = 10
  408.             Symbol type   = File        Value  = 0
  409.  
  410.         Symbol# 1: "_iobuf"
  411.             End+1 symbol  = 9
  412.             String index  = 22
  413.             Storage class = Info        Index  = 9
  414.             Symbol type   = Block       Value  = 20
  415.  
  416.         Symbol# 2: "_cnt"
  417.             Type          = int
  418.             String index  = 29
  419.             Storage class = Info        Index  = 4
  420.             Symbol type   = Member      Value  = 0
  421.  
  422.         Symbol# 3: "_ptr"
  423.             Type          = ptr to char
  424.             String index  = 34
  425.             Storage class = Info        Index  = 15
  426.             Symbol type   = Member      Value  = 32
  427.  
  428.         Symbol# 4: "_base"
  429.             Type          = ptr to char
  430.             String index  = 39
  431.             Storage class = Info        Index  = 16
  432.             Symbol type   = Member      Value  = 64
  433.  
  434.         Symbol# 5: "_bufsiz"
  435.             Type          = int
  436.             String index  = 45
  437.             Storage class = Info        Index  = 4
  438.             Symbol type   = Member      Value  = 96
  439.  
  440.         Symbol# 6: "_flag"
  441.             Type          = short
  442.             String index  = 53
  443.             Storage class = Info        Index  = 3
  444.             Symbol type   = Member      Value  = 128
  445.  
  446.         Symbol# 7: "_file"
  447.             Type          = char
  448.             String index  = 59
  449.             Storage class = Info        Index  = 2
  450.             Symbol type   = Member      Value  = 144
  451.  
  452.         Symbol# 8: ""
  453.             First symbol  = 1
  454.             String index  = 0
  455.             Storage class = Info        Index  = 1
  456.             Symbol type   = End         Value  = 0
  457.  
  458.         Symbol# 9: "/usr/include/stdio.h"
  459.             First symbol  = 0
  460.             String index  = 1
  461.             Storage class = Text        Index  = 0
  462.             Symbol type   = End         Value  = 0
  463.  
  464.     There are 25 auxiliary table entries, starting at 642.
  465.  
  466.         * #14             -1, [4095/1048575], [63 1:1 f:f:f:f:f:f]
  467.           #15          65544, [   8/     16], [ 2 0:0 1:0:0:0:0:0]
  468.           #16          65544, [   8/     16], [ 2 0:0 1:0:0:0:0:0]
  469.         * #17         196656, [  48/     48], [12 0:0 3:0:0:0:0:0]
  470.         * #18           8191, [4095/      1], [63 1:1 0:0:0:0:f:1]
  471.         * #19              1, [   1/      0], [ 0 1:0 0:0:0:0:0:0]
  472.         * #20          20479, [4095/      4], [63 1:1 0:0:0:0:f:4]
  473.         * #21              1, [   1/      0], [ 0 1:0 0:0:0:0:0:0]
  474.         * #22              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  475.         * #23              2, [   2/      0], [ 0 0:1 0:0:0:0:0:0]
  476.         * #24            160, [ 160/      0], [40 0:0 0:0:0:0:0:0]
  477.         * #25              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  478.         * #26              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  479.         * #27              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  480.         * #28              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  481.         * #29              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  482.         * #30              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  483.         * #31              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  484.         * #32              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  485.         * #33              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  486.         * #34              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  487.         * #35              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  488.         * #36              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  489.         * #37              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  490.         * #38              0, [   0/      0], [ 0 0:0 0:0:0:0:0:0]
  491.  
  492.     There are 0 procedure descriptor entries, starting at 1.
  493.  
  494.    There are 20 external symbols, starting at 1152
  495.  
  496.         Symbol# 0: "_iob"
  497.             Type          = array [3 {160}] of struct _iobuf { ifd = 1, index = 1 }
  498.             String index  = 0           Ifd    = 1
  499.             Storage class = Nil         Index  = 17
  500.             Symbol type   = Global      Value  = 60
  501.  
  502.         Symbol# 1: "fopen"
  503.             String index  = 5           Ifd    = 1
  504.             Storage class = Nil         Index  = 1048575
  505.             Symbol type   = Proc        Value  = 0
  506.  
  507.         Symbol# 2: "fdopen"
  508.             String index  = 11          Ifd    = 1
  509.             Storage class = Nil         Index  = 1048575
  510.             Symbol type   = Proc        Value  = 0
  511.  
  512.         Symbol# 3: "freopen"
  513.             String index  = 18          Ifd    = 1
  514.             Storage class = Nil         Index  = 1048575
  515.             Symbol type   = Proc        Value  = 0
  516.  
  517.         Symbol# 4: "popen"
  518.             String index  = 26          Ifd    = 1
  519.             Storage class = Nil         Index  = 1048575
  520.             Symbol type   = Proc        Value  = 0
  521.  
  522.         Symbol# 5: "tmpfile"
  523.             String index  = 32          Ifd    = 1
  524.             Storage class = Nil         Index  = 1048575
  525.             Symbol type   = Proc        Value  = 0
  526.  
  527.         Symbol# 6: "ftell"
  528.             String index  = 40          Ifd    = 1
  529.             Storage class = Nil         Index  = 1048575
  530.             Symbol type   = Proc        Value  = 0
  531.  
  532.         Symbol# 7: "rewind"
  533.             String index  = 46          Ifd    = 1
  534.             Storage class = Nil         Index  = 1048575
  535.             Symbol type   = Proc        Value  = 0
  536.  
  537.         Symbol# 8: "setbuf"
  538.             String index  = 53          Ifd    = 1
  539.             Storage class = Nil         Index  = 1048575
  540.             Symbol type   = Proc        Value  = 0
  541.  
  542.         Symbol# 9: "setbuffer"
  543.             String index  = 60          Ifd    = 1
  544.             Storage class = Nil         Index  = 1048575
  545.             Symbol type   = Proc        Value  = 0
  546.  
  547.         Symbol# 10: "setlinebuf"
  548.             String index  = 70          Ifd    = 1
  549.             Storage class = Nil         Index  = 1048575
  550.             Symbol type   = Proc        Value  = 0
  551.  
  552.         Symbol# 11: "fgets"
  553.             String index  = 81          Ifd    = 1
  554.             Storage class = Nil         Index  = 1048575
  555.             Symbol type   = Proc        Value  = 0
  556.  
  557.         Symbol# 12: "gets"
  558.             String index  = 87          Ifd    = 1
  559.             Storage class = Nil         Index  = 1048575
  560.             Symbol type   = Proc        Value  = 0
  561.  
  562.         Symbol# 13: "ctermid"
  563.             String index  = 92          Ifd    = 1
  564.             Storage class = Nil         Index  = 1048575
  565.             Symbol type   = Proc        Value  = 0
  566.  
  567.         Symbol# 14: "cuserid"
  568.             String index  = 100         Ifd    = 1
  569.             Storage class = Nil         Index  = 1048575
  570.             Symbol type   = Proc        Value  = 0
  571.  
  572.         Symbol# 15: "tempnam"
  573.             String index  = 108         Ifd    = 1
  574.             Storage class = Nil         Index  = 1048575
  575.             Symbol type   = Proc        Value  = 0
  576.  
  577.         Symbol# 16: "tmpnam"
  578.             String index  = 116         Ifd    = 1
  579.             Storage class = Nil         Index  = 1048575
  580.             Symbol type   = Proc        Value  = 0
  581.  
  582.         Symbol# 17: "sprintf"
  583.             String index  = 123         Ifd    = 1
  584.             Storage class = Nil         Index  = 1048575
  585.             Symbol type   = Proc        Value  = 0
  586.  
  587.         Symbol# 18: "main"
  588.             Type          = int
  589.             String index  = 131         Ifd    = 0
  590.             Storage class = Text        Index  = 1
  591.             Symbol type   = Proc        Value  = 0
  592.  
  593.         Symbol# 19: "printf"
  594.             String index  = 136         Ifd    = 0
  595.             Storage class = Undefined   Index  = 1048575
  596.             Symbol type   = Proc        Value  = 0
  597.  
  598.    The following auxiliary table entries were unused:
  599.  
  600.     #0               0  0x00000000  void
  601.     #2               8  0x00000008  char
  602.     #3              16  0x00000010  short
  603.     #4              24  0x00000018  int
  604.     #5              32  0x00000020  long
  605.     #6              40  0x00000028  float
  606.     #7              44  0x0000002c  double
  607.     #8              12  0x0000000c  unsigned char
  608.     #9              20  0x00000014  unsigned short
  609.     #10             28  0x0000001c  unsigned int
  610.     #11             36  0x00000024  unsigned long
  611.     #14              0  0x00000000  void
  612.     #15             24  0x00000018  int
  613.     #19             32  0x00000020  long
  614.     #20             40  0x00000028  float
  615.     #21             44  0x0000002c  double
  616.     #22             12  0x0000000c  unsigned char
  617.     #23             20  0x00000014  unsigned short
  618.     #24             28  0x0000001c  unsigned int
  619.     #25             36  0x00000024  unsigned long
  620.     #26             48  0x00000030  struct no name { ifd = -1, index = 1048575 }
  621. */
  622. /* Redefinition of of storage classes as an enumeration for better
  623.    debugging.  */
  624.  
  625. typedef enum sc {
  626.   sc_Nil         = scNil,         /* no storage class */
  627.   sc_Text        = scText,        /* text symbol */
  628.   sc_Data        = scData,        /* initialized data symbol */
  629.   sc_Bss         = scBss,         /* un-initialized data symbol */
  630.   sc_Register    = scRegister,    /* value of symbol is register number */
  631.   sc_Abs         = scAbs,         /* value of symbol is absolute */
  632.   sc_Undefined   = scUndefined,   /* who knows? */
  633.   sc_CdbLocal    = scCdbLocal,    /* variable's value is IN se->va.?? */
  634.   sc_Bits        = scBits,        /* this is a bit field */
  635.   sc_CdbSystem   = scCdbSystem,   /* value is IN CDB's address space */
  636.   sc_RegImage    = scRegImage,    /* register value saved on stack */
  637.   sc_Info        = scInfo,        /* symbol contains debugger information */
  638.   sc_UserStruct  = scUserStruct,  /* addr in struct user for current process */
  639.   sc_SData       = scSData,       /* load time only small data */
  640.   sc_SBss        = scSBss,        /* load time only small common */
  641.   sc_RData       = scRData,       /* load time only read only data */
  642.   sc_Var         = scVar,         /* Var parameter (fortran,pascal) */
  643.   sc_Common      = scCommon,      /* common variable */
  644.   sc_SCommon     = scSCommon,     /* small common */
  645.   sc_VarRegister = scVarRegister, /* Var parameter in a register */
  646.   sc_Variant     = scVariant,     /* Variant record */
  647.   sc_SUndefined  = scSUndefined,  /* small undefined(external) data */
  648.   sc_Init        = scInit,        /* .init section symbol */
  649.   sc_Max         = scMax          /* Max storage class+1 */
  650. } sc_t;
  651.  
  652. /* Redefinition of symbol type.  */
  653.  
  654. typedef enum st {
  655.   st_Nil        = stNil,        /* Nuthin' special */
  656.   st_Global     = stGlobal,     /* external symbol */
  657.   st_Static     = stStatic,     /* static */
  658.   st_Param      = stParam,      /* procedure argument */
  659.   st_Local      = stLocal,      /* local variable */
  660.   st_Label      = stLabel,      /* label */
  661.   st_Proc       = stProc,       /*     "      "  Procedure */
  662.   st_Block      = stBlock,      /* beginning of block */
  663.   st_End        = stEnd,        /* end (of anything) */
  664.   st_Member     = stMember,     /* member (of anything  - struct/union/enum */
  665.   st_Typedef    = stTypedef,    /* type definition */
  666.   st_File       = stFile,       /* file name */
  667.   st_RegReloc   = stRegReloc,   /* register relocation */
  668.   st_Forward    = stForward,    /* forwarding address */
  669.   st_StaticProc = stStaticProc, /* load time only static procs */
  670.   st_Constant   = stConstant,   /* const */
  671.   st_Str        = stStr,        /* string */
  672.   st_Number     = stNumber,     /* pure number (ie. 4 NOR 2+2) */
  673.   st_Expr       = stExpr,       /* 2+2 vs. 4 */
  674.   st_Type       = stType,       /* post-coercion SER */
  675.   st_Max        = stMax         /* max type+1 */
  676. } st_t;
  677.  
  678. /* Redefinition of type qualifiers.  */
  679.  
  680. typedef enum tq {
  681.   tq_Nil        = tqNil,        /* bt is what you see */
  682.   tq_Ptr        = tqPtr,        /* pointer */
  683.   tq_Proc       = tqProc,       /* procedure */
  684.   tq_Array      = tqArray,      /* duh */
  685.   tq_Far        = tqFar,        /* longer addressing - 8086/8 land */
  686.   tq_Vol        = tqVol,        /* volatile */
  687.   tq_Max        = tqMax         /* Max type qualifier+1 */
  688. } tq_t;
  689.  
  690. /* Redefinition of basic types.  */
  691.  
  692. typedef enum bt {
  693.   bt_Nil        = btNil,        /* undefined */
  694.   bt_Adr        = btAdr,        /* address - integer same size as pointer */
  695.   bt_Char       = btChar,       /* character */
  696.   bt_UChar      = btUChar,      /* unsigned character */
  697.   bt_Short      = btShort,      /* short */
  698.   bt_UShort     = btUShort,     /* unsigned short */
  699.   bt_Int        = btInt,        /* int */
  700.   bt_UInt       = btUInt,       /* unsigned int */
  701.   bt_Long       = btLong,       /* long */
  702.   bt_ULong      = btULong,      /* unsigned long */
  703.   bt_Float      = btFloat,      /* float (real) */
  704.   bt_Double     = btDouble,     /* Double (real) */
  705.   bt_Struct     = btStruct,     /* Structure (Record) */
  706.   bt_Union      = btUnion,      /* Union (variant) */
  707.   bt_Enum       = btEnum,       /* Enumerated */
  708.   bt_Typedef    = btTypedef,    /* defined via a typedef, isymRef points */
  709.   bt_Range      = btRange,      /* subrange of int */
  710.   bt_Set        = btSet,        /* pascal sets */
  711.   bt_Complex    = btComplex,    /* fortran complex */
  712.   bt_DComplex   = btDComplex,   /* fortran double complex */
  713.   bt_Indirect   = btIndirect,   /* forward or unnamed typedef */
  714.   bt_FixedDec   = btFixedDec,   /* Fixed Decimal */
  715.   bt_FloatDec   = btFloatDec,   /* Float Decimal */
  716.   bt_String     = btString,     /* Varying Length Character String */
  717.   bt_Bit        = btBit,        /* Aligned Bit String */
  718.   bt_Picture    = btPicture,    /* Picture */
  719.   bt_Void       = btVoid,       /* Void */
  720.   bt_Max        = btMax         /* Max basic type+1 */
  721. } bt_t;
  722.  
  723. #define N_TQ itqMax
  724.  
  725. /* States for whether to hash type or not.  */
  726. typedef enum hash_state {
  727.   hash_no       = 0,            /* Don't hash type */
  728.   hash_yes      = 1,            /* OK to hash type, or use previous hash */
  729.   hash_record   = 2             /* OK to record hash, but don't use prev.  */
  730. } hash_state_t;
  731.  
  732. /* Types of different sized allocation requests.  */
  733. enum alloc_type {
  734.   alloc_type_none,              /* dummy value */
  735.   alloc_type_scope,             /* nested scopes linked list */
  736.   alloc_type_vlinks,            /* glue linking pages in varray */
  737.   alloc_type_shash,             /* string hash element */
  738.   alloc_type_thash,             /* type hash element */
  739.   alloc_type_tag,               /* struct/union/tag element */
  740.   alloc_type_forward,           /* element to hold unknown tag */
  741.   alloc_type_thead,             /* head of type hash list */
  742.   alloc_type_varray,            /* general varray allocation */
  743.   alloc_type_lineno,            /* line number list */
  744.   alloc_type_last               /* last+1 element for array bounds */
  745. };
  746.  
  747. /* Types of auxiliary type information.  */
  748. enum aux_type {
  749.   aux_tir,                      /* TIR type information */
  750.   aux_rndx,                     /* relative index into symbol table */
  751.   aux_dnLow,                    /* low dimension */
  752.   aux_dnHigh,                   /* high dimension */
  753.   aux_isym,                     /* symbol table index (end of proc) */
  754.   aux_iss,                      /* index into string space (not used) */
  755.   aux_width,                    /* width for non-default sized struc fields */
  756.   aux_count                     /* count of ranges for variant arm */
  757. };
  758. /* Structures to provide n-number of virtual arrays, each of which can
  759.    grow linearly, and which are written in the object file as
  760.    sequential pages.  On systems with a BSD malloc, the
  761.    MAX_CLUSTER_PAGES should be 1 less than a power of two, since
  762.    malloc adds it's overhead, and rounds up to the next power of 2.
  763.    Pages are linked together via a linked list.
  764.  
  765.    If PAGE_SIZE is > 4096, the string length in the shash_t structure
  766.    can't be represented (assuming there are strings > 4096 bytes).  */
  767.  
  768. /* FIXME: Yes, there can be such strings while emitting C++ class debug
  769.    info.  Templates are the offender here, the test case in question
  770.    having a mangled class name of
  771.  
  772.      t7rb_tree4Z4xkeyZt4pair2ZC4xkeyZt7xsocket1Z4UserZt9select1st2Zt4pair\
  773.      2ZC4xkeyZt7xsocket1Z4UserZ4xkeyZt4less1Z4xkey
  774.  
  775.    Repeat that a couple dozen times while listing the class members and
  776.    you've got strings over 4k.  Hack around this for now by increasing
  777.    the page size.  A proper solution would abandon this structure scheme
  778.    certainly for very large strings, and possibly entirely.  */
  779.  
  780. #ifndef PAGE_SIZE
  781. #define PAGE_SIZE (8*1024)      /* size of varray pages */
  782. #endif
  783.  
  784. #define PAGE_USIZE ((unsigned long) PAGE_SIZE)
  785.  
  786. #ifndef MAX_CLUSTER_PAGES       /* # pages to get from system */
  787. #define MAX_CLUSTER_PAGES 63
  788. #endif
  789.  
  790. /* Linked list connecting separate page allocations.  */
  791. typedef struct vlinks {
  792.   struct vlinks *prev;          /* previous set of pages */
  793.   struct vlinks *next;          /* next set of pages */
  794.   union  page   *datum;         /* start of page */
  795.   unsigned long  start_index;   /* starting index # of page */
  796. } vlinks_t;
  797.  
  798. /* Virtual array header.  */
  799. typedef struct varray {
  800.   vlinks_t      *first;                 /* first page link */
  801.   vlinks_t      *last;                  /* last page link */
  802.   unsigned long  num_allocated;         /* # objects allocated */
  803.   unsigned short object_size;           /* size in bytes of each object */
  804.   unsigned short objects_per_page;      /* # objects that can fit on a page */
  805.   unsigned short objects_last_page;     /* # objects allocated on last page */
  806. } varray_t;
  807.  
  808. #ifndef MALLOC_CHECK
  809. #define OBJECTS_PER_PAGE(type) (PAGE_SIZE / sizeof (type))
  810. #else
  811. #define OBJECTS_PER_PAGE(type) ((sizeof (type) > 1) ? 1 : PAGE_SIZE)
  812. #endif
  813.  
  814. #define INIT_VARRAY(type) {     /* macro to initialize a varray */      \
  815.   (vlinks_t *)0,                /* first */                             \
  816.   (vlinks_t *)0,                /* last */                              \
  817.   0,                            /* num_allocated */                     \
  818.   sizeof (type),                /* object_size */                       \
  819.   OBJECTS_PER_PAGE (type),      /* objects_per_page */                  \
  820.   OBJECTS_PER_PAGE (type),      /* objects_last_page */                 \
  821. }
  822.  
  823. /* Master type for indexes within the symbol table.  */
  824. typedef unsigned long symint_t;
  825.  
  826. /* Linked list support for nested scopes (file, block, structure, etc.).  */
  827. typedef struct scope {
  828.   struct scope  *prev;          /* previous scope level */
  829.   struct scope  *free;          /* free list pointer */
  830.   struct localsym *lsym;        /* pointer to local symbol node */
  831.   st_t           type;          /* type of the node */
  832. } scope_t;
  833.  
  834. /* For a local symbol we store a gas symbol as well as the debugging
  835.    information we generate.  The gas symbol will be NULL if this is
  836.    only a debugging symbol.  */
  837. typedef struct localsym {
  838.   const char *name;             /* symbol name */
  839.   symbolS *as_sym;              /* symbol as seen by gas */
  840.   bfd_vma addend;               /* addend to as_sym value */
  841.   struct efdr *file_ptr;        /* file pointer */
  842.   struct ecoff_proc *proc_ptr;  /* proc pointer */
  843.   struct localsym *begin_ptr;   /* symbol at start of block */
  844.   struct ecoff_aux *index_ptr;  /* index value to be filled in */
  845.   struct forward *forward_ref;  /* forward references to this symbol */
  846.   long sym_index;               /* final symbol index */
  847.   EXTR ecoff_sym;               /* ECOFF debugging symbol */
  848. } localsym_t;
  849.  
  850. /* For aux information we keep the type and the data.  */
  851. typedef struct ecoff_aux {
  852.   enum aux_type type;           /* aux type */
  853.   AUXU data;                    /* aux data */
  854. } aux_t;
  855.  
  856. /* For a procedure we store the gas symbol as well as the PDR
  857.    debugging information.  */
  858. typedef struct ecoff_proc {
  859.   localsym_t *sym;              /* associated symbol */
  860.   PDR pdr;                      /* ECOFF debugging info */
  861. } proc_t;
  862.  
  863. /* Number of proc_t structures allocated.  */
  864. static unsigned long proc_cnt;
  865.  
  866. /* Forward reference list for tags referenced, but not yet defined.  */
  867. typedef struct forward {
  868.   struct forward *next;         /* next forward reference */
  869.   struct forward *free;         /* free list pointer */
  870.   aux_t          *ifd_ptr;      /* pointer to store file index */
  871.   aux_t          *index_ptr;    /* pointer to store symbol index */
  872. } forward_t;
  873.  
  874. /* Linked list support for tags.  The first tag in the list is always
  875.    the current tag for that block.  */
  876. typedef struct tag {
  877.   struct tag     *free;         /* free list pointer */
  878.   struct shash   *hash_ptr;     /* pointer to the hash table head */
  879.   struct tag     *same_name;    /* tag with same name in outer scope */
  880.   struct tag     *same_block;   /* next tag defined in the same block.  */
  881.   struct forward *forward_ref;  /* list of forward references */
  882.   bt_t            basic_type;   /* bt_Struct, bt_Union, or bt_Enum */
  883.   symint_t        ifd;          /* file # tag defined in */
  884.   localsym_t     *sym;          /* file's local symbols */
  885. } tag_t;
  886.  
  887. /* Head of a block's linked list of tags.  */
  888. typedef struct thead {
  889.   struct thead  *prev;          /* previous block */
  890.   struct thead  *free;          /* free list pointer */
  891.   struct tag    *first_tag;     /* first tag in block defined */
  892. } thead_t;
  893.  
  894. /* Union containing pointers to each the small structures which are freed up.  */
  895. typedef union small_free {
  896.   scope_t       *f_scope;       /* scope structure */
  897.   thead_t       *f_thead;       /* tag head structure */
  898.   tag_t         *f_tag;         /* tag element structure */
  899.   forward_t     *f_forward;     /* forward tag reference */
  900. } small_free_t;
  901.  
  902. /* String hash table entry.  */
  903.  
  904. typedef struct shash {
  905.   char          *string;        /* string we are hashing */
  906.   symint_t       indx;          /* index within string table */
  907.   EXTR          *esym_ptr;      /* global symbol pointer */
  908.   localsym_t    *sym_ptr;       /* local symbol pointer */
  909.   localsym_t    *end_ptr;       /* symbol pointer to end block */
  910.   tag_t         *tag_ptr;       /* tag pointer */
  911.   proc_t        *proc_ptr;      /* procedure descriptor pointer */
  912. } shash_t;
  913.  
  914. /* Type hash table support.  The size of the hash table must fit
  915.    within a page with the other extended file descriptor information.
  916.    Because unique types which are hashed are fewer in number than
  917.    strings, we use a smaller hash value.  */
  918.  
  919. #define HASHBITS 30
  920.  
  921. #ifndef THASH_SIZE
  922. #define THASH_SIZE 113
  923. #endif
  924.  
  925. typedef struct thash {
  926.   struct thash  *next;          /* next hash value */
  927.   AUXU           type;          /* type we are hashing */
  928.   symint_t       indx;          /* index within string table */
  929. } thash_t;
  930.  
  931. /* Extended file descriptor that contains all of the support necessary
  932.    to add things to each file separately.  */
  933. typedef struct efdr {
  934.   FDR            fdr;           /* File header to be written out */
  935.   FDR           *orig_fdr;      /* original file header */
  936.   char          *name;          /* filename */
  937.   int            fake;          /* whether this is faked .file */
  938.   symint_t       void_type;     /* aux. pointer to 'void' type */
  939.   symint_t       int_type;      /* aux. pointer to 'int' type */
  940.   scope_t       *cur_scope;     /* current nested scopes */
  941.   symint_t       file_index;    /* current file number */
  942.   int            nested_scopes; /* # nested scopes */
  943.   varray_t       strings;       /* local strings */
  944.   varray_t       symbols;       /* local symbols */
  945.   varray_t       procs;         /* procedures */
  946.   varray_t       aux_syms;      /* auxiliary symbols */
  947.   struct efdr   *next_file;     /* next file descriptor */
  948.                                 /* string/type hash tables */
  949.   struct hash_control *str_hash;        /* string hash table */
  950.   thash_t       *thash_head[THASH_SIZE];
  951. } efdr_t;
  952.  
  953. /* Pre-initialized extended file structure.  */
  954. static const efdr_t init_file = {
  955.   {                     /* FDR structure */
  956.     0,                  /* adr:         memory address of beginning of file */
  957.     0,                  /* rss:         file name (of source, if known) */
  958.     0,                  /* issBase:     file's string space */
  959.     0,                  /* cbSs:        number of bytes in the ss */
  960.     0,                  /* isymBase:    beginning of symbols */
  961.     0,                  /* csym:        count file's of symbols */
  962.     0,                  /* ilineBase:   file's line symbols */
  963.     0,                  /* cline:       count of file's line symbols */
  964.     0,                  /* ioptBase:    file's optimization entries */
  965.     0,                  /* copt:        count of file's optimization entries */
  966.     0,                  /* ipdFirst:    start of procedures for this file */
  967.     0,                  /* cpd:         count of procedures for this file */
  968.     0,                  /* iauxBase:    file's auxiliary entries */
  969.     0,                  /* caux:        count of file's auxiliary entries */
  970.     0,                  /* rfdBase:     index into the file indirect table */
  971.     0,                  /* crfd:        count file indirect entries */
  972.     langC,              /* lang:        language for this file */
  973.     1,                  /* fMerge:      whether this file can be merged */
  974.     0,                  /* fReadin:     true if read in (not just created) */
  975.     TARGET_BYTES_BIG_ENDIAN,  /* fBigendian:    if 1, compiled on big endian machine */
  976.     GLEVEL_2,           /* glevel:      level this file was compiled with */
  977.     0,                  /* reserved:    reserved for future use */
  978.     0,                  /* cbLineOffset: byte offset from header for this file ln's */
  979.     0,                  /* cbLine:      size of lines for this file */
  980.   },
  981.  
  982.   (FDR *)0,             /* orig_fdr:    original file header pointer */
  983.   (char *)0,            /* name:        pointer to filename */
  984.   0,                    /* fake:        whether this is a faked .file */
  985.   0,                    /* void_type:   ptr to aux node for void type */
  986.   0,                    /* int_type:    ptr to aux node for int type */
  987.   (scope_t *)0,         /* cur_scope:   current scope being processed */
  988.   0,                    /* file_index:  current file # */
  989.   0,                    /* nested_scopes: # nested scopes */
  990.   INIT_VARRAY (char),   /* strings:     local string varray */
  991.   INIT_VARRAY (localsym_t),     /* symbols:     local symbols varray */
  992.   INIT_VARRAY (proc_t), /* procs:       procedure varray */
  993.   INIT_VARRAY (aux_t),  /* aux_syms:    auxiliary symbols varray */
  994.  
  995.   (struct efdr *)0,     /* next_file:   next file structure */
  996.  
  997.   (struct hash_control *)0,     /* str_hash:    string hash table */
  998.   { 0 },                /* thash_head:  type hash table */
  999. };
  1000.  
  1001. static efdr_t *first_file;                      /* first file descriptor */
  1002. static efdr_t **last_file_ptr = &first_file;    /* file descriptor tail */
  1003.  
  1004. /* Line number information is kept in a list until the assembly is
  1005.    finished.  */
  1006. typedef struct lineno_list {
  1007.   struct lineno_list *next;     /* next element in list */
  1008.   efdr_t *file;                 /* file this line is in */
  1009.   proc_t *proc;                 /* procedure this line is in */
  1010.   fragS *frag;                  /* fragment this line number is in */
  1011.   unsigned long paddr;          /* offset within fragment */
  1012.   long lineno;                  /* actual line number */
  1013. } lineno_list_t;
  1014.  
  1015. static lineno_list_t *first_lineno;
  1016. static lineno_list_t *last_lineno;
  1017. static lineno_list_t **last_lineno_ptr = &first_lineno;
  1018.  
  1019. /* Sometimes there will be some .loc statements before a .ent.  We
  1020.    keep them in this list so that we can fill in the procedure pointer
  1021.    after we see the .ent.  */
  1022. static lineno_list_t *noproc_lineno;
  1023.  
  1024. /* Union of various things that are held in pages.  */
  1025. typedef union page {
  1026.   char          byte    [ PAGE_SIZE ];
  1027.   unsigned char ubyte   [ PAGE_SIZE ];
  1028.   efdr_t        file    [ PAGE_SIZE / sizeof (efdr_t)        ];
  1029.   FDR           ofile   [ PAGE_SIZE / sizeof (FDR)           ];
  1030.   proc_t        proc    [ PAGE_SIZE / sizeof (proc_t)        ];
  1031.   localsym_t    sym     [ PAGE_SIZE / sizeof (localsym_t)    ];
  1032.   aux_t         aux     [ PAGE_SIZE / sizeof (aux_t)         ];
  1033.   DNR           dense   [ PAGE_SIZE / sizeof (DNR)           ];
  1034.   scope_t       scope   [ PAGE_SIZE / sizeof (scope_t)       ];
  1035.   vlinks_t      vlinks  [ PAGE_SIZE / sizeof (vlinks_t)      ];
  1036.   shash_t       shash   [ PAGE_SIZE / sizeof (shash_t)       ];
  1037.   thash_t       thash   [ PAGE_SIZE / sizeof (thash_t)       ];
  1038.   tag_t         tag     [ PAGE_SIZE / sizeof (tag_t)         ];
  1039.   forward_t     forward [ PAGE_SIZE / sizeof (forward_t)     ];
  1040.   thead_t       thead   [ PAGE_SIZE / sizeof (thead_t)       ];
  1041.   lineno_list_t lineno  [ PAGE_SIZE / sizeof (lineno_list_t) ];
  1042. } page_type;
  1043.  
  1044. /* Structure holding allocation information for small sized structures.  */
  1045. typedef struct alloc_info {
  1046.   char          *alloc_name;    /* name of this allocation type (must be first) */
  1047.   page_type     *cur_page;      /* current page being allocated from */
  1048.   small_free_t   free_list;     /* current free list if any */
  1049.   int            unallocated;   /* number of elements unallocated on page */
  1050.   int            total_alloc;   /* total number of allocations */
  1051.   int            total_free;    /* total number of frees */
  1052.   int            total_pages;   /* total number of pages allocated */
  1053. } alloc_info_t;
  1054.  
  1055. /* Type information collected together.  */
  1056. typedef struct type_info {
  1057.   bt_t        basic_type;               /* basic type */
  1058.   int         orig_type;                /* original COFF-based type */
  1059.   int         num_tq;                   /* # type qualifiers */
  1060.   int         num_dims;                 /* # dimensions */
  1061.   int         num_sizes;                /* # sizes */
  1062.   int         extra_sizes;              /* # extra sizes not tied with dims */
  1063.   tag_t *     tag_ptr;                  /* tag pointer */
  1064.   int         bitfield;                 /* symbol is a bitfield */
  1065.   tq_t        type_qualifiers[N_TQ];    /* type qualifiers (ptr, func, array)*/
  1066.   symint_t    dimensions     [N_TQ];    /* dimensions for each array */
  1067.   symint_t    sizes          [N_TQ+2];  /* sizes of each array slice + size of
  1068.                                            struct/union/enum + bitfield size */
  1069. } type_info_t;
  1070.  
  1071. /* Pre-initialized type_info struct.  */
  1072. static const type_info_t type_info_init = {
  1073.   bt_Nil,                               /* basic type */
  1074.   T_NULL,                               /* original COFF-based type */
  1075.   0,                                    /* # type qualifiers */
  1076.   0,                                    /* # dimensions */
  1077.   0,                                    /* # sizes */
  1078.   0,                                    /* sizes not tied with dims */
  1079.   NULL,                                 /* ptr to tag */
  1080.   0,                                    /* bitfield */
  1081.   {                                     /* type qualifiers */
  1082.     tq_Nil,
  1083.     tq_Nil,
  1084.     tq_Nil,
  1085.     tq_Nil,
  1086.     tq_Nil,
  1087.     tq_Nil,
  1088.   },
  1089.   {                                     /* dimensions */
  1090.     0,
  1091.     0,
  1092.     0,
  1093.     0,
  1094.     0,
  1095.     0
  1096.   },
  1097.   {                                     /* sizes */
  1098.     0,
  1099.     0,
  1100.     0,
  1101.     0,
  1102.     0,
  1103.     0,
  1104.     0,
  1105.     0,
  1106.   },
  1107. };
  1108.  
  1109. /* Global hash table for the tags table and global table for file
  1110.    descriptors.  */
  1111.  
  1112. static varray_t file_desc = INIT_VARRAY (efdr_t);
  1113.  
  1114. static struct hash_control *tag_hash;
  1115.  
  1116. /* Static types for int and void.  Also, remember the last function's
  1117.    type (which is set up when we encounter the declaration for the
  1118.    function, and used when the end block for the function is emitted.  */
  1119.  
  1120. static type_info_t int_type_info;
  1121. static type_info_t void_type_info;
  1122. static type_info_t last_func_type_info;
  1123. static symbolS *last_func_sym_value;
  1124.  
  1125. /* Convert COFF basic type to ECOFF basic type.  The T_NULL type
  1126.    really should use bt_Void, but this causes the current ecoff GDB to
  1127.    issue unsupported type messages, and the Ultrix 4.00 dbx (aka MIPS
  1128.    2.0) doesn't understand it, even though the compiler generates it.
  1129.    Maybe this will be fixed in 2.10 or 2.20 of the MIPS compiler
  1130.    suite, but for now go with what works.
  1131.  
  1132.    It would make sense for the .type and .scl directives to use the
  1133.    ECOFF numbers directly, rather than using the COFF numbers and
  1134.    mapping them.  Unfortunately, this is historically what mips-tfile
  1135.    expects, and changing gcc now would be a considerable pain (the
  1136.    native compiler generates debugging information internally, rather
  1137.    than via the assembler, so it will never use .type or .scl).  */
  1138.  
  1139. static const bt_t map_coff_types[] = {
  1140.   bt_Nil,                       /* T_NULL */
  1141.   bt_Nil,                       /* T_ARG */
  1142.   bt_Char,                      /* T_CHAR */
  1143.   bt_Short,                     /* T_SHORT */
  1144.   bt_Int,                       /* T_INT */
  1145.   bt_Long,                      /* T_LONG */
  1146.   bt_Float,                     /* T_FLOAT */
  1147.   bt_Double,                    /* T_DOUBLE */
  1148.   bt_Struct,                    /* T_STRUCT */
  1149.   bt_Union,                     /* T_UNION */
  1150.   bt_Enum,                      /* T_ENUM */
  1151.   bt_Enum,                      /* T_MOE */
  1152.   bt_UChar,                     /* T_UCHAR */
  1153.   bt_UShort,                    /* T_USHORT */
  1154.   bt_UInt,                      /* T_UINT */
  1155.   bt_ULong                      /* T_ULONG */
  1156. };
  1157.  
  1158. /* Convert COFF storage class to ECOFF storage class.  */
  1159. static const sc_t map_coff_storage[] = {
  1160.   sc_Nil,                       /*   0: C_NULL */
  1161.   sc_Abs,                       /*   1: C_AUTO    auto var */
  1162.   sc_Undefined,                 /*   2: C_EXT     external */
  1163.   sc_Data,                      /*   3: C_STAT    static */
  1164.   sc_Register,                  /*   4: C_REG     register */
  1165.   sc_Undefined,                 /*   5: C_EXTDEF  ??? */
  1166.   sc_Text,                      /*   6: C_LABEL   label */
  1167.   sc_Text,                      /*   7: C_ULABEL  user label */
  1168.   sc_Info,                      /*   8: C_MOS     member of struct */
  1169.   sc_Abs,                       /*   9: C_ARG     argument */
  1170.   sc_Info,                      /*  10: C_STRTAG  struct tag */
  1171.   sc_Info,                      /*  11: C_MOU     member of union */
  1172.   sc_Info,                      /*  12: C_UNTAG   union tag */
  1173.   sc_Info,                      /*  13: C_TPDEF   typedef */
  1174.   sc_Data,                      /*  14: C_USTATIC ??? */
  1175.   sc_Info,                      /*  15: C_ENTAG   enum tag */
  1176.   sc_Info,                      /*  16: C_MOE     member of enum */
  1177.   sc_Register,                  /*  17: C_REGPARM register parameter */
  1178.   sc_Bits,                      /*  18; C_FIELD   bitfield */
  1179.   sc_Nil,                       /*  19 */
  1180.   sc_Nil,                       /*  20 */
  1181.   sc_Nil,                       /*  21 */
  1182.   sc_Nil,                       /*  22 */
  1183.   sc_Nil,                       /*  23 */
  1184.   sc_Nil,                       /*  24 */
  1185.   sc_Nil,                       /*  25 */
  1186.   sc_Nil,                       /*  26 */
  1187.   sc_Nil,                       /*  27 */
  1188.   sc_Nil,                       /*  28 */
  1189.   sc_Nil,                       /*  29 */
  1190.   sc_Nil,                       /*  30 */
  1191.   sc_Nil,                       /*  31 */
  1192.   sc_Nil,                       /*  32 */
  1193.   sc_Nil,                       /*  33 */
  1194.   sc_Nil,                       /*  34 */
  1195.   sc_Nil,                       /*  35 */
  1196.   sc_Nil,                       /*  36 */
  1197.   sc_Nil,                       /*  37 */
  1198.   sc_Nil,                       /*  38 */
  1199.   sc_Nil,                       /*  39 */
  1200.   sc_Nil,                       /*  40 */
  1201.   sc_Nil,                       /*  41 */
  1202.   sc_Nil,                       /*  42 */
  1203.   sc_Nil,                       /*  43 */
  1204.   sc_Nil,                       /*  44 */
  1205.   sc_Nil,                       /*  45 */
  1206.   sc_Nil,                       /*  46 */
  1207.   sc_Nil,                       /*  47 */
  1208.   sc_Nil,                       /*  48 */
  1209.   sc_Nil,                       /*  49 */
  1210.   sc_Nil,                       /*  50 */
  1211.   sc_Nil,                       /*  51 */
  1212.   sc_Nil,                       /*  52 */
  1213.   sc_Nil,                       /*  53 */
  1214.   sc_Nil,                       /*  54 */
  1215.   sc_Nil,                       /*  55 */
  1216.   sc_Nil,                       /*  56 */
  1217.   sc_Nil,                       /*  57 */
  1218.   sc_Nil,                       /*  58 */
  1219.   sc_Nil,                       /*  59 */
  1220.   sc_Nil,                       /*  60 */
  1221.   sc_Nil,                       /*  61 */
  1222.   sc_Nil,                       /*  62 */
  1223.   sc_Nil,                       /*  63 */
  1224.   sc_Nil,                       /*  64 */
  1225.   sc_Nil,                       /*  65 */
  1226.   sc_Nil,                       /*  66 */
  1227.   sc_Nil,                       /*  67 */
  1228.   sc_Nil,                       /*  68 */
  1229.   sc_Nil,                       /*  69 */
  1230.   sc_Nil,                       /*  70 */
  1231.   sc_Nil,                       /*  71 */
  1232.   sc_Nil,                       /*  72 */
  1233.   sc_Nil,                       /*  73 */
  1234.   sc_Nil,                       /*  74 */
  1235.   sc_Nil,                       /*  75 */
  1236.   sc_Nil,                       /*  76 */
  1237.   sc_Nil,                       /*  77 */
  1238.   sc_Nil,                       /*  78 */
  1239.   sc_Nil,                       /*  79 */
  1240.   sc_Nil,                       /*  80 */
  1241.   sc_Nil,                       /*  81 */
  1242.   sc_Nil,                       /*  82 */
  1243.   sc_Nil,                       /*  83 */
  1244.   sc_Nil,                       /*  84 */
  1245.   sc_Nil,                       /*  85 */
  1246.   sc_Nil,                       /*  86 */
  1247.   sc_Nil,                       /*  87 */
  1248.   sc_Nil,                       /*  88 */
  1249.   sc_Nil,                       /*  89 */
  1250.   sc_Nil,                       /*  90 */
  1251.   sc_Nil,                       /*  91 */
  1252.   sc_Nil,                       /*  92 */
  1253.   sc_Nil,                       /*  93 */
  1254.   sc_Nil,                       /*  94 */
  1255.   sc_Nil,                       /*  95 */
  1256.   sc_Nil,                       /*  96 */
  1257.   sc_Nil,                       /*  97 */
  1258.   sc_Nil,                       /*  98 */
  1259.   sc_Nil,                       /*  99 */
  1260.   sc_Text,                      /* 100: C_BLOCK  block start/end */
  1261.   sc_Text,                      /* 101: C_FCN    function start/end */
  1262.   sc_Info,                      /* 102: C_EOS    end of struct/union/enum */
  1263.   sc_Nil,                       /* 103: C_FILE   file start */
  1264.   sc_Nil,                       /* 104: C_LINE   line number */
  1265.   sc_Nil,                       /* 105: C_ALIAS  combined type info */
  1266.   sc_Nil,                       /* 106: C_HIDDEN ??? */
  1267. };
  1268.  
  1269. /* Convert COFF storage class to ECOFF symbol type.  */
  1270. static const st_t map_coff_sym_type[] = {
  1271.   st_Nil,                       /*   0: C_NULL */
  1272.   st_Local,                     /*   1: C_AUTO    auto var */
  1273.   st_Global,                    /*   2: C_EXT     external */
  1274.   st_Static,                    /*   3: C_STAT    static */
  1275.   st_Local,                     /*   4: C_REG     register */
  1276.   st_Global,                    /*   5: C_EXTDEF  ??? */
  1277.   st_Label,                     /*   6: C_LABEL   label */
  1278.   st_Label,                     /*   7: C_ULABEL  user label */
  1279.   st_Member,                    /*   8: C_MOS     member of struct */
  1280.   st_Param,                     /*   9: C_ARG     argument */
  1281.   st_Block,                     /*  10: C_STRTAG  struct tag */
  1282.   st_Member,                    /*  11: C_MOU     member of union */
  1283.   st_Block,                     /*  12: C_UNTAG   union tag */
  1284.   st_Typedef,                   /*  13: C_TPDEF   typedef */
  1285.   st_Static,                    /*  14: C_USTATIC ??? */
  1286.   st_Block,                     /*  15: C_ENTAG   enum tag */
  1287.   st_Member,                    /*  16: C_MOE     member of enum */
  1288.   st_Param,                     /*  17: C_REGPARM register parameter */
  1289.   st_Member,                    /*  18; C_FIELD   bitfield */
  1290.   st_Nil,                       /*  19 */
  1291.   st_Nil,                       /*  20 */
  1292.   st_Nil,                       /*  21 */
  1293.   st_Nil,                       /*  22 */
  1294.   st_Nil,                       /*  23 */
  1295.   st_Nil,                       /*  24 */
  1296.   st_Nil,                       /*  25 */
  1297.   st_Nil,                       /*  26 */
  1298.   st_Nil,                       /*  27 */
  1299.   st_Nil,                       /*  28 */
  1300.   st_Nil,                       /*  29 */
  1301.   st_Nil,                       /*  30 */
  1302.   st_Nil,                       /*  31 */
  1303.   st_Nil,                       /*  32 */
  1304.   st_Nil,                       /*  33 */
  1305.   st_Nil,                       /*  34 */
  1306.   st_Nil,                       /*  35 */
  1307.   st_Nil,                       /*  36 */
  1308.   st_Nil,                       /*  37 */
  1309.   st_Nil,                       /*  38 */
  1310.   st_Nil,                       /*  39 */
  1311.   st_Nil,                       /*  40 */
  1312.   st_Nil,                       /*  41 */
  1313.   st_Nil,                       /*  42 */
  1314.   st_Nil,                       /*  43 */
  1315.   st_Nil,                       /*  44 */
  1316.   st_Nil,                       /*  45 */
  1317.   st_Nil,                       /*  46 */
  1318.   st_Nil,                       /*  47 */
  1319.   st_Nil,                       /*  48 */
  1320.   st_Nil,                       /*  49 */
  1321.   st_Nil,                       /*  50 */
  1322.   st_Nil,                       /*  51 */
  1323.   st_Nil,                       /*  52 */
  1324.   st_Nil,                       /*  53 */
  1325.   st_Nil,                       /*  54 */
  1326.   st_Nil,                       /*  55 */
  1327.   st_Nil,                       /*  56 */
  1328.   st_Nil,                       /*  57 */
  1329.   st_Nil,                       /*  58 */
  1330.   st_Nil,                       /*  59 */
  1331.   st_Nil,                       /*  60 */
  1332.   st_Nil,                       /*  61 */
  1333.   st_Nil,                       /*  62 */
  1334.   st_Nil,                       /*  63 */
  1335.   st_Nil,                       /*  64 */
  1336.   st_Nil,                       /*  65 */
  1337.   st_Nil,                       /*  66 */
  1338.   st_Nil,                       /*  67 */
  1339.   st_Nil,                       /*  68 */
  1340.   st_Nil,                       /*  69 */
  1341.   st_Nil,                       /*  70 */
  1342.   st_Nil,                       /*  71 */
  1343.   st_Nil,                       /*  72 */
  1344.   st_Nil,                       /*  73 */
  1345.   st_Nil,                       /*  74 */
  1346.   st_Nil,                       /*  75 */
  1347.   st_Nil,                       /*  76 */
  1348.   st_Nil,                       /*  77 */
  1349.   st_Nil,                       /*  78 */
  1350.   st_Nil,                       /*  79 */
  1351.   st_Nil,                       /*  80 */
  1352.   st_Nil,                       /*  81 */
  1353.   st_Nil,                       /*  82 */
  1354.   st_Nil,                       /*  83 */
  1355.   st_Nil,                       /*  84 */
  1356.   st_Nil,                       /*  85 */
  1357.   st_Nil,                       /*  86 */
  1358.   st_Nil,                       /*  87 */
  1359.   st_Nil,                       /*  88 */
  1360.   st_Nil,                       /*  89 */
  1361.   st_Nil,                       /*  90 */
  1362.   st_Nil,                       /*  91 */
  1363.   st_Nil,                       /*  92 */
  1364.   st_Nil,                       /*  93 */
  1365.   st_Nil,                       /*  94 */
  1366.   st_Nil,                       /*  95 */
  1367.   st_Nil,                       /*  96 */
  1368.   st_Nil,                       /*  97 */
  1369.   st_Nil,                       /*  98 */
  1370.   st_Nil,                       /*  99 */
  1371.   st_Block,                     /* 100: C_BLOCK  block start/end */
  1372.   st_Proc,                      /* 101: C_FCN    function start/end */
  1373.   st_End,                       /* 102: C_EOS    end of struct/union/enum */
  1374.   st_File,                      /* 103: C_FILE   file start */
  1375.   st_Nil,                       /* 104: C_LINE   line number */
  1376.   st_Nil,                       /* 105: C_ALIAS  combined type info */
  1377.   st_Nil,                       /* 106: C_HIDDEN ??? */
  1378. };
  1379.  
  1380. /* Keep track of different sized allocation requests.  */
  1381. static alloc_info_t alloc_counts[(int) alloc_type_last];
  1382. /* Record whether we have seen any debugging information.  */
  1383. int ecoff_debugging_seen = 0;
  1384.  
  1385. /* Various statics.  */
  1386. static efdr_t  *cur_file_ptr    = (efdr_t *) 0; /* current file desc. header */
  1387. static proc_t  *cur_proc_ptr    = (proc_t *) 0; /* current procedure header */
  1388. static proc_t  *first_proc_ptr  = (proc_t *) 0; /* first procedure header */
  1389. static thead_t *top_tag_head    = (thead_t *) 0; /* top level tag head */
  1390. static thead_t *cur_tag_head    = (thead_t *) 0; /* current tag head */
  1391. #ifdef ECOFF_DEBUG
  1392. static int      debug           = 0;            /* trace functions */
  1393. #endif
  1394. static int      stabs_seen      = 0;            /* != 0 if stabs have been seen */
  1395.  
  1396. static int current_file_idx;
  1397. static const char *current_stabs_filename;
  1398.  
  1399. /* Pseudo symbol to use when putting stabs into the symbol table.  */
  1400. #ifndef STABS_SYMBOL
  1401. #define STABS_SYMBOL "@stabs"
  1402. #endif
  1403.  
  1404. static char stabs_symbol[] = STABS_SYMBOL;
  1405. /* Prototypes for functions defined in this file.  */
  1406.  
  1407. static void add_varray_page (varray_t *vp);
  1408. static symint_t add_string (varray_t *vp,
  1409.                             struct hash_control *hash_tbl,
  1410.                             const char *str,
  1411.                             shash_t **ret_hash);
  1412. static localsym_t *add_ecoff_symbol (const char *str, st_t type,
  1413.                                      sc_t storage, symbolS *sym,
  1414.                                      bfd_vma addend, symint_t value,
  1415.                                      symint_t indx);
  1416. static symint_t add_aux_sym_symint (symint_t aux_word);
  1417. static symint_t add_aux_sym_rndx (int file_index, symint_t sym_index);
  1418. static symint_t add_aux_sym_tir (type_info_t *t,
  1419.                                  hash_state_t state,
  1420.                                  thash_t **hash_tbl);
  1421. static tag_t *get_tag (const char *tag, localsym_t *sym, bt_t basic_type);
  1422. static void add_unknown_tag (tag_t *ptag);
  1423. static void add_procedure (char *func);
  1424. static void add_file (const char *file_name, int indx, int fake);
  1425. #ifdef ECOFF_DEBUG
  1426. static char *sc_to_string (sc_t storage_class);
  1427. static char *st_to_string (st_t symbol_type);
  1428. #endif
  1429. static void mark_stabs (int);
  1430. static char *ecoff_add_bytes (char **buf, char **bufend,
  1431.                               char *bufptr, unsigned long need);
  1432. static unsigned long ecoff_padding_adjust
  1433.   (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1434.    unsigned long offset, char **bufptrptr);
  1435. static unsigned long ecoff_build_lineno
  1436.   (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1437.    unsigned long offset, long *linecntptr);
  1438. static unsigned long ecoff_build_symbols
  1439.   (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1440.    unsigned long offset);
  1441. static unsigned long ecoff_build_procs
  1442.   (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1443.    unsigned long offset);
  1444. static unsigned long ecoff_build_aux
  1445.   (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1446.    unsigned long offset);
  1447. static unsigned long ecoff_build_strings (char **buf, char **bufend,
  1448.                                           unsigned long offset,
  1449.                                           varray_t *vp);
  1450. static unsigned long ecoff_build_ss
  1451.   (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1452.    unsigned long offset);
  1453. static unsigned long ecoff_build_fdr
  1454.   (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1455.    unsigned long offset);
  1456. static void ecoff_setup_ext (void);
  1457. static page_type *allocate_cluster (unsigned long npages);
  1458. static page_type *allocate_page (void);
  1459. static scope_t *allocate_scope (void);
  1460. static void free_scope (scope_t *ptr);
  1461. static vlinks_t *allocate_vlinks (void);
  1462. static shash_t *allocate_shash (void);
  1463. static thash_t *allocate_thash (void);
  1464. static tag_t *allocate_tag (void);
  1465. static void free_tag (tag_t *ptr);
  1466. static forward_t *allocate_forward (void);
  1467. static thead_t *allocate_thead (void);
  1468. static void free_thead (thead_t *ptr);
  1469. static lineno_list_t *allocate_lineno_list (void);
  1470. /* This function should be called when the assembler starts up.  */
  1471.  
  1472. void
  1473. ecoff_read_begin_hook (void)
  1474. {
  1475.   tag_hash = hash_new ();
  1476.   top_tag_head = allocate_thead ();
  1477.   top_tag_head->first_tag = (tag_t *) NULL;
  1478.   top_tag_head->free = (thead_t *) NULL;
  1479.   top_tag_head->prev = cur_tag_head;
  1480.   cur_tag_head = top_tag_head;
  1481. }
  1482.  
  1483. /* This function should be called when a symbol is created.  */
  1484.  
  1485. void
  1486. ecoff_symbol_new_hook (symbolS *symbolP)
  1487. {
  1488.   OBJ_SYMFIELD_TYPE *obj;
  1489.  
  1490.   /* Make sure that we have a file pointer, but only if we have seen a
  1491.      file.  If we haven't seen a file, then this is a probably special
  1492.      symbol created by md_begin which may required special handling at
  1493.      some point.  Creating a dummy file with a dummy name is certainly
  1494.      wrong.  */
  1495.   if (cur_file_ptr == (efdr_t *) NULL
  1496.       && seen_at_least_1_file ())
  1497.     add_file ((const char *) NULL, 0, 1);
  1498.   obj = symbol_get_obj (symbolP);
  1499.   obj->ecoff_file = cur_file_ptr;
  1500.   obj->ecoff_symbol = NULL;
  1501.   obj->ecoff_extern_size = 0;
  1502. }
  1503.  
  1504. void
  1505. ecoff_symbol_clone_hook (symbolS *newsymP, symbolS *orgsymP)
  1506. {
  1507.   OBJ_SYMFIELD_TYPE *n, *o;
  1508.  
  1509.   n = symbol_get_obj (newsymP);
  1510.   o = symbol_get_obj (orgsymP);
  1511.   memcpy (n, o, sizeof *n);
  1512. }
  1513. /* Add a page to a varray object.  */
  1514.  
  1515. static void
  1516. add_varray_page (varray_t *vp /* varray to add page to */)
  1517. {
  1518.   vlinks_t *new_links = allocate_vlinks ();
  1519.  
  1520. #ifdef MALLOC_CHECK
  1521.   if (vp->object_size > 1)
  1522.     new_links->datum = (page_type *) xcalloc (1, vp->object_size);
  1523.   else
  1524. #endif
  1525.     new_links->datum = allocate_page ();
  1526.  
  1527.   alloc_counts[(int) alloc_type_varray].total_alloc++;
  1528.   alloc_counts[(int) alloc_type_varray].total_pages++;
  1529.  
  1530.   new_links->start_index = vp->num_allocated;
  1531.   vp->objects_last_page = 0;
  1532.  
  1533.   if (vp->first == (vlinks_t *) NULL)           /* first allocation? */
  1534.     vp->first = vp->last = new_links;
  1535.   else
  1536.     {                                           /* 2nd or greater allocation */
  1537.       new_links->prev = vp->last;
  1538.       vp->last->next = new_links;
  1539.       vp->last = new_links;
  1540.     }
  1541. }
  1542. /* Add a string (and null pad) to one of the string tables.  */
  1543.  
  1544. static symint_t
  1545. add_string (varray_t *vp,                       /* string obstack */
  1546.             struct hash_control *hash_tbl,      /* ptr to hash table */
  1547.             const char *str,                    /* string */
  1548.             shash_t **ret_hash                  /* return hash pointer */)
  1549. {
  1550.   register unsigned long len = strlen (str);
  1551.   register shash_t *hash_ptr;
  1552.  
  1553.   if (len >= PAGE_USIZE)
  1554.     as_fatal (_("string too big (%lu bytes)"), len);
  1555.  
  1556.   hash_ptr = (shash_t *) hash_find (hash_tbl, str);
  1557.   if (hash_ptr == (shash_t *) NULL)
  1558.     {
  1559.       register const char *err;
  1560.  
  1561.       if (vp->objects_last_page + len >= PAGE_USIZE)
  1562.         {
  1563.           vp->num_allocated =
  1564.             ((vp->num_allocated + PAGE_USIZE - 1) / PAGE_USIZE) * PAGE_USIZE;
  1565.           add_varray_page (vp);
  1566.         }
  1567.  
  1568.       hash_ptr = allocate_shash ();
  1569.       hash_ptr->indx = vp->num_allocated;
  1570.  
  1571.       hash_ptr->string = &vp->last->datum->byte[vp->objects_last_page];
  1572.  
  1573.       vp->objects_last_page += len + 1;
  1574.       vp->num_allocated += len + 1;
  1575.  
  1576.       strcpy (hash_ptr->string, str);
  1577.  
  1578.       err = hash_insert (hash_tbl, str, (char *) hash_ptr);
  1579.       if (err)
  1580.         as_fatal (_("inserting \"%s\" into string hash table: %s"),
  1581.                   str, err);
  1582.     }
  1583.  
  1584.   if (ret_hash != (shash_t **) NULL)
  1585.     *ret_hash = hash_ptr;
  1586.  
  1587.   return hash_ptr->indx;
  1588. }
  1589. /* Add debugging information for a symbol.  */
  1590.  
  1591. static localsym_t *
  1592. add_ecoff_symbol (const char *str,      /* symbol name */
  1593.                   st_t type,            /* symbol type */
  1594.                   sc_t storage,         /* storage class */
  1595.                   symbolS *sym_value,   /* associated symbol.  */
  1596.                   bfd_vma addend,       /* addend to sym_value.  */
  1597.                   symint_t value,       /* value of symbol */
  1598.                   symint_t indx         /* index to local/aux. syms */)
  1599. {
  1600.   localsym_t *psym;
  1601.   register scope_t *pscope;
  1602.   register thead_t *ptag_head;
  1603.   register tag_t *ptag;
  1604.   register tag_t *ptag_next;
  1605.   register varray_t *vp;
  1606.   register int scope_delta = 0;
  1607.   shash_t *hash_ptr = (shash_t *) NULL;
  1608.  
  1609.   if (cur_file_ptr == (efdr_t *) NULL)
  1610.     as_fatal (_("no current file pointer"));
  1611.  
  1612.   vp = &cur_file_ptr->symbols;
  1613.  
  1614.   if (vp->objects_last_page == vp->objects_per_page)
  1615.     add_varray_page (vp);
  1616.  
  1617.   psym = &vp->last->datum->sym[vp->objects_last_page++];
  1618.  
  1619.   if (str == (const char *) NULL && sym_value != (symbolS *) NULL)
  1620.     psym->name = S_GET_NAME (sym_value);
  1621.   else
  1622.     psym->name = str;
  1623.   psym->as_sym = sym_value;
  1624.   if (sym_value != (symbolS *) NULL)
  1625.     symbol_get_obj (sym_value)->ecoff_symbol = psym;
  1626.   psym->addend = addend;
  1627.   psym->file_ptr = cur_file_ptr;
  1628.   psym->proc_ptr = cur_proc_ptr;
  1629.   psym->begin_ptr = (localsym_t *) NULL;
  1630.   psym->index_ptr = (aux_t *) NULL;
  1631.   psym->forward_ref = (forward_t *) NULL;
  1632.   psym->sym_index = -1;
  1633.   memset (&psym->ecoff_sym, 0, sizeof (EXTR));
  1634.   psym->ecoff_sym.asym.value = value;
  1635.   psym->ecoff_sym.asym.st = (unsigned) type;
  1636.   psym->ecoff_sym.asym.sc = (unsigned) storage;
  1637.   psym->ecoff_sym.asym.index = indx;
  1638.  
  1639.   /* If there is an associated symbol, we wait until the end of the
  1640.      assembly before deciding where to put the name (it may be just an
  1641.      external symbol).  Otherwise, this is just a debugging symbol and
  1642.      the name should go with the current file.  */
  1643.   if (sym_value == (symbolS *) NULL)
  1644.     psym->ecoff_sym.asym.iss = ((str == (const char *) NULL)
  1645.                                 ? 0
  1646.                                 : add_string (&cur_file_ptr->strings,
  1647.                                               cur_file_ptr->str_hash,
  1648.                                               str,
  1649.                                               &hash_ptr));
  1650.  
  1651.   ++vp->num_allocated;
  1652.  
  1653.   if (ECOFF_IS_STAB (&psym->ecoff_sym.asym))
  1654.     return psym;
  1655.  
  1656.   /* Save the symbol within the hash table if this is a static
  1657.      item, and it has a name.  */
  1658.   if (hash_ptr != (shash_t *) NULL
  1659.       && (type == st_Global || type == st_Static || type == st_Label
  1660.           || type == st_Proc || type == st_StaticProc))
  1661.     hash_ptr->sym_ptr = psym;
  1662.  
  1663.   /* push or pop a scope if appropriate.  */
  1664.   switch (type)
  1665.     {
  1666.     default:
  1667.       break;
  1668.  
  1669.     case st_File:                       /* beginning of file */
  1670.     case st_Proc:                       /* procedure */
  1671.     case st_StaticProc:                 /* static procedure */
  1672.     case st_Block:                      /* begin scope */
  1673.       pscope = allocate_scope ();
  1674.       pscope->prev = cur_file_ptr->cur_scope;
  1675.       pscope->lsym = psym;
  1676.       pscope->type = type;
  1677.       cur_file_ptr->cur_scope = pscope;
  1678.  
  1679.       if (type != st_File)
  1680.         scope_delta = 1;
  1681.  
  1682.       /* For every block type except file, struct, union, or
  1683.          enumeration blocks, push a level on the tag stack.  We omit
  1684.          file types, so that tags can span file boundaries.  */
  1685.       if (type != st_File && storage != sc_Info)
  1686.         {
  1687.           ptag_head = allocate_thead ();
  1688.           ptag_head->first_tag = 0;
  1689.           ptag_head->prev = cur_tag_head;
  1690.           cur_tag_head = ptag_head;
  1691.         }
  1692.       break;
  1693.  
  1694.     case st_End:
  1695.       pscope = cur_file_ptr->cur_scope;
  1696.       if (pscope == (scope_t *) NULL)
  1697.         as_fatal (_("too many st_End's"));
  1698.       else
  1699.         {
  1700.           st_t begin_type = (st_t) pscope->lsym->ecoff_sym.asym.st;
  1701.  
  1702.           psym->begin_ptr = pscope->lsym;
  1703.  
  1704.           if (begin_type != st_File)
  1705.             scope_delta = -1;
  1706.  
  1707.           /* Except for file, structure, union, or enumeration end
  1708.              blocks remove all tags created within this scope.  */
  1709.           if (begin_type != st_File && storage != sc_Info)
  1710.             {
  1711.               ptag_head = cur_tag_head;
  1712.               cur_tag_head = ptag_head->prev;
  1713.  
  1714.               for (ptag = ptag_head->first_tag;
  1715.                    ptag != (tag_t *) NULL;
  1716.                    ptag = ptag_next)
  1717.                 {
  1718.                   if (ptag->forward_ref != (forward_t *) NULL)
  1719.                     add_unknown_tag (ptag);
  1720.  
  1721.                   ptag_next = ptag->same_block;
  1722.                   ptag->hash_ptr->tag_ptr = ptag->same_name;
  1723.                   free_tag (ptag);
  1724.                 }
  1725.  
  1726.               free_thead (ptag_head);
  1727.             }
  1728.  
  1729.           cur_file_ptr->cur_scope = pscope->prev;
  1730.  
  1731.           /* block begin gets next sym #.  This is set when we know
  1732.              the symbol index value.  */
  1733.  
  1734.           /* Functions push two or more aux words as follows:
  1735.              1st word: index+1 of the end symbol (filled in later).
  1736.              2nd word: type of the function (plus any aux words needed).
  1737.              Also, tie the external pointer back to the function begin symbol.  */
  1738.           if (begin_type != st_File && begin_type != st_Block)
  1739.             {
  1740.               symint_t ty;
  1741.               varray_t *svp = &cur_file_ptr->aux_syms;
  1742.  
  1743.               pscope->lsym->ecoff_sym.asym.index = add_aux_sym_symint (0);
  1744.               pscope->lsym->index_ptr =
  1745.                 &svp->last->datum->aux[svp->objects_last_page - 1];
  1746.               ty = add_aux_sym_tir (&last_func_type_info,
  1747.                                     hash_no,
  1748.                                     &cur_file_ptr->thash_head[0]);
  1749.               (void) ty;
  1750. /* This seems to be unnecessary.  I'm not even sure what it is
  1751.  * intended to do.  It's from mips-tfile.
  1752.  *            if (last_func_sym_value != (symbolS *) NULL)
  1753.  *              {
  1754.  *                last_func_sym_value->ifd = cur_file_ptr->file_index;
  1755.  *                last_func_sym_value->index = ty;
  1756.  *              }
  1757.  */
  1758.             }
  1759.  
  1760.           free_scope (pscope);
  1761.         }
  1762.     }
  1763.  
  1764.   cur_file_ptr->nested_scopes += scope_delta;
  1765.  
  1766. #ifdef ECOFF_DEBUG
  1767.   if (debug && type != st_File
  1768.       && (debug > 2 || type == st_Block || type == st_End
  1769.           || type == st_Proc || type == st_StaticProc))
  1770.     {
  1771.       char *sc_str = sc_to_string (storage);
  1772.       char *st_str = st_to_string (type);
  1773.       int depth = cur_file_ptr->nested_scopes + (scope_delta < 0);
  1774.  
  1775.       fprintf (stderr,
  1776.                "\tlsym\tv= %10ld, depth= %2d, sc= %-12s",
  1777.                value, depth, sc_str);
  1778.  
  1779.       if (str_start && str_end_p1 - str_start > 0)
  1780.         fprintf (stderr, " st= %-11s name= %.*s\n",
  1781.                  st_str, str_end_p1 - str_start, str_start);
  1782.       else
  1783.         {
  1784.           unsigned long len = strlen (st_str);
  1785.           fprintf (stderr, " st= %.*s\n", len - 1, st_str);
  1786.         }
  1787.     }
  1788. #endif
  1789.  
  1790.   return psym;
  1791. }
  1792. /* Add an auxiliary symbol (passing a symint).  This is actually used
  1793.    for integral aux types, not just symints.  */
  1794.  
  1795. static symint_t
  1796. add_aux_sym_symint (symint_t aux_word /* auxiliary information word */)
  1797. {
  1798.   register varray_t *vp;
  1799.   register aux_t *aux_ptr;
  1800.  
  1801.   if (cur_file_ptr == (efdr_t *) NULL)
  1802.     as_fatal (_("no current file pointer"));
  1803.  
  1804.   vp = &cur_file_ptr->aux_syms;
  1805.  
  1806.   if (vp->objects_last_page == vp->objects_per_page)
  1807.     add_varray_page (vp);
  1808.  
  1809.   aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1810.   aux_ptr->type = aux_isym;
  1811.   aux_ptr->data.isym = aux_word;
  1812.  
  1813.   return vp->num_allocated++;
  1814. }
  1815.  
  1816. /* Add an auxiliary symbol (passing a file/symbol index combo).  */
  1817.  
  1818. static symint_t
  1819. add_aux_sym_rndx (int file_index, symint_t sym_index)
  1820. {
  1821.   register varray_t *vp;
  1822.   register aux_t *aux_ptr;
  1823.  
  1824.   if (cur_file_ptr == (efdr_t *) NULL)
  1825.     as_fatal (_("no current file pointer"));
  1826.  
  1827.   vp = &cur_file_ptr->aux_syms;
  1828.  
  1829.   if (vp->objects_last_page == vp->objects_per_page)
  1830.     add_varray_page (vp);
  1831.  
  1832.   aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1833.   aux_ptr->type = aux_rndx;
  1834.   aux_ptr->data.rndx.rfd   = file_index;
  1835.   aux_ptr->data.rndx.index = sym_index;
  1836.  
  1837.   return vp->num_allocated++;
  1838. }
  1839. /* Add an auxiliary symbol (passing the basic type and possibly
  1840.    type qualifiers).  */
  1841.  
  1842. static symint_t
  1843. add_aux_sym_tir (type_info_t *t,        /* current type information */
  1844.                  hash_state_t state,    /* whether to hash type or not */
  1845.                  thash_t **hash_tbl     /* pointer to hash table to use */)
  1846. {
  1847.   register varray_t *vp;
  1848.   register aux_t *aux_ptr;
  1849.   static AUXU init_aux;
  1850.   symint_t ret;
  1851.   int i;
  1852.   AUXU aux;
  1853.  
  1854.   if (cur_file_ptr == (efdr_t *) NULL)
  1855.     as_fatal (_("no current file pointer"));
  1856.  
  1857.   vp = &cur_file_ptr->aux_syms;
  1858.  
  1859.   aux = init_aux;
  1860.   aux.ti.bt = (int) t->basic_type;
  1861.   aux.ti.continued = 0;
  1862.   aux.ti.fBitfield = t->bitfield;
  1863.  
  1864.   aux.ti.tq0 = (int) t->type_qualifiers[0];
  1865.   aux.ti.tq1 = (int) t->type_qualifiers[1];
  1866.   aux.ti.tq2 = (int) t->type_qualifiers[2];
  1867.   aux.ti.tq3 = (int) t->type_qualifiers[3];
  1868.   aux.ti.tq4 = (int) t->type_qualifiers[4];
  1869.   aux.ti.tq5 = (int) t->type_qualifiers[5];
  1870.  
  1871.   /* For anything that adds additional information, we must not hash,
  1872.      so check here, and reset our state.  */
  1873.  
  1874.   if (state != hash_no
  1875.       && (t->type_qualifiers[0] == tq_Array
  1876.           || t->type_qualifiers[1] == tq_Array
  1877.           || t->type_qualifiers[2] == tq_Array
  1878.           || t->type_qualifiers[3] == tq_Array
  1879.           || t->type_qualifiers[4] == tq_Array
  1880.           || t->type_qualifiers[5] == tq_Array
  1881.           || t->basic_type == bt_Struct
  1882.           || t->basic_type == bt_Union
  1883.           || t->basic_type == bt_Enum
  1884.           || t->bitfield
  1885.           || t->num_dims > 0))
  1886.     state = hash_no;
  1887.  
  1888.   /* See if we can hash this type, and save some space, but some types
  1889.      can't be hashed (because they contain arrays or continuations),
  1890.      and others can be put into the hash list, but cannot use existing
  1891.      types because other aux entries precede this one.  */
  1892.  
  1893.   if (state != hash_no)
  1894.     {
  1895.       register thash_t *hash_ptr;
  1896.       register symint_t hi;
  1897.  
  1898.       hi = aux.isym & ((1 << HASHBITS) - 1);
  1899.       hi %= THASH_SIZE;
  1900.  
  1901.       for (hash_ptr = hash_tbl[hi];
  1902.            hash_ptr != (thash_t *)0;
  1903.            hash_ptr = hash_ptr->next)
  1904.         {
  1905.           if (aux.isym == hash_ptr->type.isym)
  1906.             break;
  1907.         }
  1908.  
  1909.       if (hash_ptr != (thash_t *) NULL && state == hash_yes)
  1910.         return hash_ptr->indx;
  1911.  
  1912.       if (hash_ptr == (thash_t *) NULL)
  1913.         {
  1914.           hash_ptr = allocate_thash ();
  1915.           hash_ptr->next = hash_tbl[hi];
  1916.           hash_ptr->type = aux;
  1917.           hash_ptr->indx = vp->num_allocated;
  1918.           hash_tbl[hi] = hash_ptr;
  1919.         }
  1920.     }
  1921.  
  1922.   /* Everything is set up, add the aux symbol.  */
  1923.   if (vp->objects_last_page == vp->objects_per_page)
  1924.     add_varray_page (vp);
  1925.  
  1926.   aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1927.   aux_ptr->type = aux_tir;
  1928.   aux_ptr->data = aux;
  1929.  
  1930.   ret = vp->num_allocated++;
  1931.  
  1932.   /* Add bitfield length if it exists.
  1933.  
  1934.      NOTE:  Mips documentation claims bitfield goes at the end of the
  1935.      AUX record, but the DECstation compiler emits it here.
  1936.      (This would only make a difference for enum bitfields.)
  1937.  
  1938.      Also note:  We use the last size given since gcc may emit 2
  1939.      for an enum bitfield.  */
  1940.  
  1941.   if (t->bitfield)
  1942.     (void) add_aux_sym_symint ((symint_t) t->sizes[t->num_sizes - 1]);
  1943.  
  1944.   /* Add tag information if needed.  Structure, union, and enum
  1945.      references add 2 aux symbols: a [file index, symbol index]
  1946.      pointer to the structure type, and the current file index.  */
  1947.  
  1948.   if (t->basic_type == bt_Struct
  1949.       || t->basic_type == bt_Union
  1950.       || t->basic_type == bt_Enum)
  1951.     {
  1952.       register symint_t file_index = t->tag_ptr->ifd;
  1953.       register localsym_t *sym = t->tag_ptr->sym;
  1954.       register forward_t *forward_ref = allocate_forward ();
  1955.  
  1956.       if (sym != (localsym_t *) NULL)
  1957.         {
  1958.           forward_ref->next = sym->forward_ref;
  1959.           sym->forward_ref = forward_ref;
  1960.         }
  1961.       else
  1962.         {
  1963.           forward_ref->next = t->tag_ptr->forward_ref;
  1964.           t->tag_ptr->forward_ref = forward_ref;
  1965.         }
  1966.  
  1967.       (void) add_aux_sym_rndx (ST_RFDESCAPE, indexNil);
  1968.       forward_ref->index_ptr
  1969.         = &vp->last->datum->aux[vp->objects_last_page - 1];
  1970.  
  1971.       (void) add_aux_sym_symint (file_index);
  1972.       forward_ref->ifd_ptr
  1973.         = &vp->last->datum->aux[vp->objects_last_page - 1];
  1974.     }
  1975.  
  1976.   /* Add information about array bounds if they exist.  */
  1977.   for (i = 0; i < t->num_dims; i++)
  1978.     {
  1979.       (void) add_aux_sym_rndx (ST_RFDESCAPE,
  1980.                                cur_file_ptr->int_type);
  1981.  
  1982.       (void) add_aux_sym_symint (cur_file_ptr->file_index);     /* file index*/
  1983.       (void) add_aux_sym_symint ((symint_t) 0);                 /* low bound */
  1984.       (void) add_aux_sym_symint (t->dimensions[i] - 1);         /* high bound*/
  1985.       (void) add_aux_sym_symint ((t->dimensions[i] == 0)        /* stride */
  1986.                                  ? 0
  1987.                                  : (t->sizes[i] * 8) / t->dimensions[i]);
  1988.     };
  1989.  
  1990.   /* NOTE:  Mips documentation claims that the bitfield width goes here.
  1991.      But it needs to be emitted earlier.  */
  1992.  
  1993.   return ret;
  1994. }
  1995. /* Add a tag to the tag table (unless it already exists).  */
  1996.  
  1997. static tag_t *
  1998. get_tag (const char *tag,       /* tag name */
  1999.          localsym_t *sym,       /* tag start block */
  2000.          bt_t basic_type        /* bt_Struct, bt_Union, or bt_Enum */)
  2001. {
  2002.   shash_t *hash_ptr;
  2003.   const char *err;
  2004.   tag_t *tag_ptr;
  2005.  
  2006.   if (cur_file_ptr == (efdr_t *) NULL)
  2007.     as_fatal (_("no current file pointer"));
  2008.  
  2009.   hash_ptr = (shash_t *) hash_find (tag_hash, tag);
  2010.  
  2011.   if (hash_ptr != (shash_t *) NULL
  2012.       && hash_ptr->tag_ptr != (tag_t *) NULL)
  2013.     {
  2014.       tag_ptr = hash_ptr->tag_ptr;
  2015.       if (sym != (localsym_t *) NULL)
  2016.         {
  2017.           tag_ptr->basic_type = basic_type;
  2018.           tag_ptr->ifd        = cur_file_ptr->file_index;
  2019.           tag_ptr->sym        = sym;
  2020.         }
  2021.       return tag_ptr;
  2022.     }
  2023.  
  2024.   if (hash_ptr == (shash_t *) NULL)
  2025.     {
  2026.       char *perm;
  2027.  
  2028.       perm = xstrdup (tag);
  2029.       hash_ptr = allocate_shash ();
  2030.       err = hash_insert (tag_hash, perm, (char *) hash_ptr);
  2031.       if (err)
  2032.         as_fatal (_("inserting \"%s\" into tag hash table: %s"),
  2033.                   tag, err);
  2034.       hash_ptr->string = perm;
  2035.     }
  2036.  
  2037.   tag_ptr = allocate_tag ();
  2038.   tag_ptr->forward_ref  = (forward_t *) NULL;
  2039.   tag_ptr->hash_ptr     = hash_ptr;
  2040.   tag_ptr->same_name    = hash_ptr->tag_ptr;
  2041.   tag_ptr->basic_type   = basic_type;
  2042.   tag_ptr->sym          = sym;
  2043.   tag_ptr->ifd          = ((sym == (localsym_t *) NULL)
  2044.                            ? (symint_t) -1
  2045.                            : cur_file_ptr->file_index);
  2046.   tag_ptr->same_block   = cur_tag_head->first_tag;
  2047.  
  2048.   cur_tag_head->first_tag = tag_ptr;
  2049.   hash_ptr->tag_ptr       = tag_ptr;
  2050.  
  2051.   return tag_ptr;
  2052. }
  2053. /* Add an unknown {struct, union, enum} tag.  */
  2054.  
  2055. static void
  2056. add_unknown_tag (tag_t *ptag /* pointer to tag information */)
  2057. {
  2058.   shash_t *hash_ptr     = ptag->hash_ptr;
  2059.   char *name            = hash_ptr->string;
  2060.   localsym_t *sym;
  2061.   forward_t **pf;
  2062.  
  2063. #ifdef ECOFF_DEBUG
  2064.   if (debug > 1)
  2065.     {
  2066.       char *agg_type = "{unknown aggregate type}";
  2067.       switch (ptag->basic_type)
  2068.         {
  2069.         case bt_Struct: agg_type = "struct";    break;
  2070.         case bt_Union:  agg_type = "union";     break;
  2071.         case bt_Enum:   agg_type = "enum";      break;
  2072.         default:                                break;
  2073.         }
  2074.  
  2075.       fprintf (stderr, "unknown %s %.*s found\n", agg_type,
  2076.                hash_ptr->len, name_start);
  2077.     }
  2078. #endif
  2079.  
  2080.   sym = add_ecoff_symbol (name,
  2081.                           st_Block,
  2082.                           sc_Info,
  2083.                           (symbolS *) NULL,
  2084.                           (bfd_vma) 0,
  2085.                           (symint_t) 0,
  2086.                           (symint_t) 0);
  2087.  
  2088.   (void) add_ecoff_symbol (name,
  2089.                            st_End,
  2090.                            sc_Info,
  2091.                            (symbolS *) NULL,
  2092.                            (bfd_vma) 0,
  2093.                            (symint_t) 0,
  2094.                            (symint_t) 0);
  2095.  
  2096.   for (pf = &sym->forward_ref; *pf != (forward_t *) NULL; pf = &(*pf)->next)
  2097.     ;
  2098.   *pf = ptag->forward_ref;
  2099. }
  2100. /* Add a procedure to the current file's list of procedures, and record
  2101.    this is the current procedure.  */
  2102.  
  2103. static void
  2104. add_procedure (char *func /* func name */)
  2105. {
  2106.   register varray_t *vp;
  2107.   register proc_t *new_proc_ptr;
  2108.   symbolS *sym;
  2109.  
  2110. #ifdef ECOFF_DEBUG
  2111.   if (debug)
  2112.     fputc ('\n', stderr);
  2113. #endif
  2114.  
  2115.   if (cur_file_ptr == (efdr_t *) NULL)
  2116.     as_fatal (_("no current file pointer"));
  2117.  
  2118.   vp = &cur_file_ptr->procs;
  2119.  
  2120.   if (vp->objects_last_page == vp->objects_per_page)
  2121.     add_varray_page (vp);
  2122.  
  2123.   cur_proc_ptr = new_proc_ptr = &vp->last->datum->proc[vp->objects_last_page++];
  2124.  
  2125.   if (first_proc_ptr == (proc_t *) NULL)
  2126.     first_proc_ptr = new_proc_ptr;
  2127.  
  2128.   vp->num_allocated++;
  2129.  
  2130.   new_proc_ptr->pdr.isym = -1;
  2131.   new_proc_ptr->pdr.iline = -1;
  2132.   new_proc_ptr->pdr.lnLow = -1;
  2133.   new_proc_ptr->pdr.lnHigh = -1;
  2134.  
  2135.   /* Set the BSF_FUNCTION flag for the symbol.  */
  2136.   sym = symbol_find_or_make (func);
  2137.   symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
  2138.  
  2139.   /* Push the start of the function.  */
  2140.   new_proc_ptr->sym = add_ecoff_symbol ((const char *) NULL, st_Proc, sc_Text,
  2141.                                         sym, (bfd_vma) 0, (symint_t) 0,
  2142.                                         (symint_t) 0);
  2143.  
  2144.   ++proc_cnt;
  2145.  
  2146.   /* Fill in the linenos preceding the .ent, if any.  */
  2147.   if (noproc_lineno != (lineno_list_t *) NULL)
  2148.     {
  2149.       lineno_list_t *l;
  2150.  
  2151.       for (l = noproc_lineno; l != (lineno_list_t *) NULL; l = l->next)
  2152.         l->proc = new_proc_ptr;
  2153.       *last_lineno_ptr = noproc_lineno;
  2154.       while (*last_lineno_ptr != NULL)
  2155.         {
  2156.           last_lineno = *last_lineno_ptr;
  2157.           last_lineno_ptr = &last_lineno->next;
  2158.         }
  2159.       noproc_lineno = (lineno_list_t *) NULL;
  2160.     }
  2161. }
  2162.  
  2163. symbolS *
  2164. ecoff_get_cur_proc_sym (void)
  2165. {
  2166.   return (cur_proc_ptr ? cur_proc_ptr->sym->as_sym : NULL);
  2167. }
  2168. /* Add a new filename, and set up all of the file relative
  2169.    virtual arrays (strings, symbols, aux syms, etc.).  Record
  2170.    where the current file structure lives.  */
  2171.  
  2172. static void
  2173. add_file (const char *file_name, int indx ATTRIBUTE_UNUSED, int fake)
  2174. {
  2175.   register int first_ch;
  2176.   register efdr_t *fil_ptr;
  2177.  
  2178. #ifdef ECOFF_DEBUG
  2179.   if (debug)
  2180.     fprintf (stderr, "\tfile\t%.*s\n", len, file_start);
  2181. #endif
  2182.  
  2183.   /* If the file name is NULL, then no .file symbol appeared, and we
  2184.      want to use the actual file name.  */
  2185.   if (file_name == (const char *) NULL)
  2186.     {
  2187.       char *file;
  2188.  
  2189.       if (first_file != (efdr_t *) NULL)
  2190.         as_fatal (_("fake .file after real one"));
  2191.       as_where (&file, (unsigned int *) NULL);
  2192.       file_name = (const char *) file;
  2193.  
  2194.       /* Automatically generate ECOFF debugging information, since I
  2195.          think that's what other ECOFF assemblers do.  We don't do
  2196.          this if we see a .file directive with a string, since that
  2197.          implies that some sort of debugging information is being
  2198.          provided.  */
  2199.       if (! symbol_table_frozen && debug_type == DEBUG_UNSPECIFIED)
  2200.         debug_type = DEBUG_ECOFF;
  2201.     }
  2202.   else if (debug_type == DEBUG_UNSPECIFIED)
  2203.     debug_type = DEBUG_NONE;
  2204.  
  2205. #ifndef NO_LISTING
  2206.   if (listing)
  2207.     listing_source_file (file_name);
  2208. #endif
  2209.  
  2210.   current_stabs_filename = file_name;
  2211.  
  2212.   /* If we're creating stabs, then we don't actually make a new FDR.
  2213.      Instead, we just create a stabs symbol.  */
  2214.   if (stabs_seen)
  2215.     {
  2216.       (void) add_ecoff_symbol (file_name, st_Nil, sc_Nil,
  2217.                                symbol_new ("L0\001", now_seg,
  2218.                                            (valueT) frag_now_fix (),
  2219.                                            frag_now),
  2220.                                (bfd_vma) 0, 0, ECOFF_MARK_STAB (N_SOL));
  2221.       return;
  2222.     }
  2223.  
  2224.   first_ch = *file_name;
  2225.  
  2226.   /* FIXME: We can't safely merge files which have line number
  2227.      information (fMerge will be zero in this case).  Otherwise, we
  2228.      get incorrect line number debugging info.  See for instance
  2229.      ecoff_build_lineno, which will end up setting all file->fdr.*
  2230.      fields multiple times, resulting in incorrect debug info.  In
  2231.      order to make this work right, all line number and symbol info
  2232.      for the same source file has to be adjacent in the object file,
  2233.      so that a single file descriptor can be used to point to them.
  2234.      This would require maintaining file specific lists of line
  2235.      numbers and symbols for each file, so that they can be merged
  2236.      together (or output together) when two .file pseudo-ops are
  2237.      merged into one file descriptor.  */
  2238.  
  2239.   /* See if the file has already been created.  */
  2240.   for (fil_ptr = first_file;
  2241.        fil_ptr != (efdr_t *) NULL;
  2242.        fil_ptr = fil_ptr->next_file)
  2243.     {
  2244.       if (first_ch == fil_ptr->name[0]
  2245.           && filename_cmp (file_name, fil_ptr->name) == 0
  2246.           && fil_ptr->fdr.fMerge)
  2247.         {
  2248.           cur_file_ptr = fil_ptr;
  2249.           if (! fake)
  2250.             cur_file_ptr->fake = 0;
  2251.           break;
  2252.         }
  2253.     }
  2254.  
  2255.   /* If this is a new file, create it.  */
  2256.   if (fil_ptr == (efdr_t *) NULL)
  2257.     {
  2258.       if (file_desc.objects_last_page == file_desc.objects_per_page)
  2259.         add_varray_page (&file_desc);
  2260.  
  2261.       fil_ptr = cur_file_ptr =
  2262.         &file_desc.last->datum->file[file_desc.objects_last_page++];
  2263.       *fil_ptr = init_file;
  2264.  
  2265.       fil_ptr->file_index = current_file_idx++;
  2266.       ++file_desc.num_allocated;
  2267.  
  2268.       fil_ptr->fake = fake;
  2269.  
  2270.       /* Allocate the string hash table.  */
  2271.       fil_ptr->str_hash = hash_new ();
  2272.  
  2273.       /* Make sure 0 byte in string table is null  */
  2274.       add_string (&fil_ptr->strings,
  2275.                   fil_ptr->str_hash,
  2276.                   "",
  2277.                   (shash_t **)0);
  2278.  
  2279.       if (strlen (file_name) > PAGE_USIZE - 2)
  2280.         as_fatal (_("filename goes over one page boundary"));
  2281.  
  2282.       /* Push the start of the filename. We assume that the filename
  2283.          will be stored at string offset 1.  */
  2284.       (void) add_ecoff_symbol (file_name, st_File, sc_Text,
  2285.                                (symbolS *) NULL, (bfd_vma) 0,
  2286.                                (symint_t) 0, (symint_t) 0);
  2287.       fil_ptr->fdr.rss = 1;
  2288.       fil_ptr->name = &fil_ptr->strings.last->datum->byte[1];
  2289.  
  2290.       /* Update the linked list of file descriptors.  */
  2291.       *last_file_ptr = fil_ptr;
  2292.       last_file_ptr = &fil_ptr->next_file;
  2293.  
  2294.       /* Add void & int types to the file (void should be first to catch
  2295.          errant 0's within the index fields).  */
  2296.       fil_ptr->void_type = add_aux_sym_tir (&void_type_info,
  2297.                                             hash_yes,
  2298.                                             &cur_file_ptr->thash_head[0]);
  2299.  
  2300.       fil_ptr->int_type = add_aux_sym_tir (&int_type_info,
  2301.                                            hash_yes,
  2302.                                            &cur_file_ptr->thash_head[0]);
  2303.     }
  2304. }
  2305.  
  2306. /* This function is called when the assembler notices a preprocessor
  2307.    directive switching to a new file.  This will not happen in
  2308.    compiler output, only in hand coded assembler.  */
  2309.  
  2310. void
  2311. ecoff_new_file (const char *name, int appfile ATTRIBUTE_UNUSED)
  2312. {
  2313.   if (cur_file_ptr != NULL && filename_cmp (cur_file_ptr->name, name) == 0)
  2314.     return;
  2315.   add_file (name, 0, 0);
  2316.  
  2317.   /* This is a hand coded assembler file, so automatically turn on
  2318.      debugging information.  */
  2319.   if (debug_type == DEBUG_UNSPECIFIED)
  2320.     debug_type = DEBUG_ECOFF;
  2321. }
  2322. #ifdef ECOFF_DEBUG
  2323.  
  2324. /* Convert storage class to string.  */
  2325.  
  2326. static char *
  2327. sc_to_string (storage_class)
  2328.      sc_t storage_class;
  2329. {
  2330.   switch (storage_class)
  2331.     {
  2332.     case sc_Nil:         return "Nil,";
  2333.     case sc_Text:        return "Text,";
  2334.     case sc_Data:        return "Data,";
  2335.     case sc_Bss:         return "Bss,";
  2336.     case sc_Register:    return "Register,";
  2337.     case sc_Abs:         return "Abs,";
  2338.     case sc_Undefined:   return "Undefined,";
  2339.     case sc_CdbLocal:    return "CdbLocal,";
  2340.     case sc_Bits:        return "Bits,";
  2341.     case sc_CdbSystem:   return "CdbSystem,";
  2342.     case sc_RegImage:    return "RegImage,";
  2343.     case sc_Info:        return "Info,";
  2344.     case sc_UserStruct:  return "UserStruct,";
  2345.     case sc_SData:       return "SData,";
  2346.     case sc_SBss:        return "SBss,";
  2347.     case sc_RData:       return "RData,";
  2348.     case sc_Var:         return "Var,";
  2349.     case sc_Common:      return "Common,";
  2350.     case sc_SCommon:     return "SCommon,";
  2351.     case sc_VarRegister: return "VarRegister,";
  2352.     case sc_Variant:     return "Variant,";
  2353.     case sc_SUndefined:  return "SUndefined,";
  2354.     case sc_Init:        return "Init,";
  2355.     case sc_Max:         return "Max,";
  2356.     }
  2357.  
  2358.   return "???,";
  2359. }
  2360.  
  2361. #endif /* DEBUG */
  2362. #ifdef ECOFF_DEBUG
  2363.  
  2364. /* Convert symbol type to string.  */
  2365.  
  2366. static char *
  2367. st_to_string (symbol_type)
  2368.      st_t symbol_type;
  2369. {
  2370.   switch (symbol_type)
  2371.     {
  2372.     case st_Nil:        return "Nil,";
  2373.     case st_Global:     return "Global,";
  2374.     case st_Static:     return "Static,";
  2375.     case st_Param:      return "Param,";
  2376.     case st_Local:      return "Local,";
  2377.     case st_Label:      return "Label,";
  2378.     case st_Proc:       return "Proc,";
  2379.     case st_Block:      return "Block,";
  2380.     case st_End:        return "End,";
  2381.     case st_Member:     return "Member,";
  2382.     case st_Typedef:    return "Typedef,";
  2383.     case st_File:       return "File,";
  2384.     case st_RegReloc:   return "RegReloc,";
  2385.     case st_Forward:    return "Forward,";
  2386.     case st_StaticProc: return "StaticProc,";
  2387.     case st_Constant:   return "Constant,";
  2388.     case st_Str:        return "String,";
  2389.     case st_Number:     return "Number,";
  2390.     case st_Expr:       return "Expr,";
  2391.     case st_Type:       return "Type,";
  2392.     case st_Max:        return "Max,";
  2393.     }
  2394.  
  2395.   return "???,";
  2396. }
  2397.  
  2398. #endif /* DEBUG */
  2399. /* Parse .begin directives which have a label as the first argument
  2400.    which gives the location of the start of the block.  */
  2401.  
  2402. void
  2403. ecoff_directive_begin (int ignore ATTRIBUTE_UNUSED)
  2404. {
  2405.   char *name;
  2406.   char name_end;
  2407.  
  2408.   if (cur_file_ptr == (efdr_t *) NULL)
  2409.     {
  2410.       as_warn (_(".begin directive without a preceding .file directive"));
  2411.       demand_empty_rest_of_line ();
  2412.       return;
  2413.     }
  2414.  
  2415.   if (cur_proc_ptr == (proc_t *) NULL)
  2416.     {
  2417.       as_warn (_(".begin directive without a preceding .ent directive"));
  2418.       demand_empty_rest_of_line ();
  2419.       return;
  2420.     }
  2421.  
  2422.   name = input_line_pointer;
  2423.   name_end = get_symbol_end ();
  2424.  
  2425.   (void) add_ecoff_symbol ((const char *) NULL, st_Block, sc_Text,
  2426.                            symbol_find_or_make (name),
  2427.                            (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  2428.  
  2429.   *input_line_pointer = name_end;
  2430.  
  2431.   /* The line number follows, but we don't use it.  */
  2432.   (void) get_absolute_expression ();
  2433.   demand_empty_rest_of_line ();
  2434. }
  2435. /* Parse .bend directives which have a label as the first argument
  2436.    which gives the location of the end of the block.  */
  2437.  
  2438. void
  2439. ecoff_directive_bend (int ignore ATTRIBUTE_UNUSED)
  2440. {
  2441.   char *name;
  2442.   char name_end;
  2443.   symbolS *endsym;
  2444.  
  2445.   if (cur_file_ptr == (efdr_t *) NULL)
  2446.     {
  2447.       as_warn (_(".bend directive without a preceding .file directive"));
  2448.       demand_empty_rest_of_line ();
  2449.       return;
  2450.     }
  2451.  
  2452.   if (cur_proc_ptr == (proc_t *) NULL)
  2453.     {
  2454.       as_warn (_(".bend directive without a preceding .ent directive"));
  2455.       demand_empty_rest_of_line ();
  2456.       return;
  2457.     }
  2458.  
  2459.   name = input_line_pointer;
  2460.   name_end = get_symbol_end ();
  2461.  
  2462.   /* The value is the distance between the .bend directive and the
  2463.      corresponding symbol.  We fill in the offset when we write out
  2464.      the symbol.  */
  2465.   endsym = symbol_find (name);
  2466.   if (endsym == (symbolS *) NULL)
  2467.     as_warn (_(".bend directive names unknown symbol"));
  2468.   else
  2469.     (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text, endsym,
  2470.                              (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  2471.  
  2472.   *input_line_pointer = name_end;
  2473.  
  2474.   /* The line number follows, but we don't use it.  */
  2475.   (void) get_absolute_expression ();
  2476.   demand_empty_rest_of_line ();
  2477. }
  2478. /* COFF debugging information is provided as a series of directives
  2479.    (.def, .scl, etc.).  We build up information as we read the
  2480.    directives in the following static variables, and file it away when
  2481.    we reach the .endef directive.  */
  2482. static char *coff_sym_name;
  2483. static type_info_t coff_type;
  2484. static sc_t coff_storage_class;
  2485. static st_t coff_symbol_typ;
  2486. static int coff_is_function;
  2487. static char *coff_tag;
  2488. static valueT coff_value;
  2489. static symbolS *coff_sym_value;
  2490. static bfd_vma coff_sym_addend;
  2491. static int coff_inside_enumeration;
  2492.  
  2493. /* Handle a .def directive: start defining a symbol.  */
  2494.  
  2495. void
  2496. ecoff_directive_def (int ignore ATTRIBUTE_UNUSED)
  2497. {
  2498.   char *name;
  2499.   char name_end;
  2500.  
  2501.   ecoff_debugging_seen = 1;
  2502.  
  2503.   SKIP_WHITESPACE ();
  2504.  
  2505.   name = input_line_pointer;
  2506.   name_end = get_symbol_end ();
  2507.  
  2508.   if (coff_sym_name != (char *) NULL)
  2509.     as_warn (_(".def pseudo-op used inside of .def/.endef; ignored"));
  2510.   else if (*name == '\0')
  2511.     as_warn (_("empty symbol name in .def; ignored"));
  2512.   else
  2513.     {
  2514.       if (coff_sym_name != (char *) NULL)
  2515.         free (coff_sym_name);
  2516.       if (coff_tag != (char *) NULL)
  2517.         free (coff_tag);
  2518.  
  2519.       coff_sym_name = xstrdup (name);
  2520.       coff_type = type_info_init;
  2521.       coff_storage_class = sc_Nil;
  2522.       coff_symbol_typ = st_Nil;
  2523.       coff_is_function = 0;
  2524.       coff_tag = (char *) NULL;
  2525.       coff_value = 0;
  2526.       coff_sym_value = (symbolS *) NULL;
  2527.       coff_sym_addend = 0;
  2528.     }
  2529.  
  2530.   *input_line_pointer = name_end;
  2531.  
  2532.   demand_empty_rest_of_line ();
  2533. }
  2534.  
  2535. /* Handle a .dim directive, used to give dimensions for an array.  The
  2536.    arguments are comma separated numbers.  mips-tfile assumes that
  2537.    there will not be more than 6 dimensions, and gdb won't read any
  2538.    more than that anyhow, so I will also make that assumption.  */
  2539.  
  2540. void
  2541. ecoff_directive_dim (int ignore ATTRIBUTE_UNUSED)
  2542. {
  2543.   int dimens[N_TQ];
  2544.   int i;
  2545.  
  2546.   if (coff_sym_name == (char *) NULL)
  2547.     {
  2548.       as_warn (_(".dim pseudo-op used outside of .def/.endef; ignored"));
  2549.       demand_empty_rest_of_line ();
  2550.       return;
  2551.     }
  2552.  
  2553.   for (i = 0; i < N_TQ; i++)
  2554.     {
  2555.       SKIP_WHITESPACE ();
  2556.       dimens[i] = get_absolute_expression ();
  2557.       if (*input_line_pointer == ',')
  2558.         ++input_line_pointer;
  2559.       else
  2560.         {
  2561.           if (*input_line_pointer != '\n'
  2562.               && *input_line_pointer != ';')
  2563.             as_warn (_("badly formed .dim directive"));
  2564.           break;
  2565.         }
  2566.     }
  2567.  
  2568.   if (i == N_TQ)
  2569.     --i;
  2570.  
  2571.   /* The dimensions are stored away in reverse order.  */
  2572.   for (; i >= 0; i--)
  2573.     {
  2574.       if (coff_type.num_dims >= N_TQ)
  2575.         {
  2576.           as_warn (_("too many .dim entries"));
  2577.           break;
  2578.         }
  2579.       coff_type.dimensions[coff_type.num_dims] = dimens[i];
  2580.       ++coff_type.num_dims;
  2581.     }
  2582.  
  2583.   demand_empty_rest_of_line ();
  2584. }
  2585.  
  2586. /* Handle a .scl directive, which sets the COFF storage class of the
  2587.    symbol.  */
  2588.  
  2589. void
  2590. ecoff_directive_scl (int ignore ATTRIBUTE_UNUSED)
  2591. {
  2592.   long val;
  2593.  
  2594.   if (coff_sym_name == (char *) NULL)
  2595.     {
  2596.       as_warn (_(".scl pseudo-op used outside of .def/.endef; ignored"));
  2597.       demand_empty_rest_of_line ();
  2598.       return;
  2599.     }
  2600.  
  2601.   val = get_absolute_expression ();
  2602.  
  2603.   coff_symbol_typ = map_coff_sym_type[val];
  2604.   coff_storage_class = map_coff_storage[val];
  2605.  
  2606.   demand_empty_rest_of_line ();
  2607. }
  2608.  
  2609. /* Handle a .size directive.  For some reason mips-tfile.c thinks that
  2610.    .size can have multiple arguments.  We humor it, although gcc will
  2611.    never generate more than one argument.  */
  2612.  
  2613. void
  2614. ecoff_directive_size (int ignore ATTRIBUTE_UNUSED)
  2615. {
  2616.   int sizes[N_TQ];
  2617.   int i;
  2618.  
  2619.   if (coff_sym_name == (char *) NULL)
  2620.     {
  2621.       as_warn (_(".size pseudo-op used outside of .def/.endef; ignored"));
  2622.       demand_empty_rest_of_line ();
  2623.       return;
  2624.     }
  2625.  
  2626.   for (i = 0; i < N_TQ; i++)
  2627.     {
  2628.       SKIP_WHITESPACE ();
  2629.       sizes[i] = get_absolute_expression ();
  2630.       if (*input_line_pointer == ',')
  2631.         ++input_line_pointer;
  2632.       else
  2633.         {
  2634.           if (*input_line_pointer != '\n'
  2635.               && *input_line_pointer != ';')
  2636.             as_warn (_("badly formed .size directive"));
  2637.           break;
  2638.         }
  2639.     }
  2640.  
  2641.   if (i == N_TQ)
  2642.     --i;
  2643.  
  2644.   /* The sizes are stored away in reverse order.  */
  2645.   for (; i >= 0; i--)
  2646.     {
  2647.       if (coff_type.num_sizes >= N_TQ)
  2648.         {
  2649.           as_warn (_("too many .size entries"));
  2650.           break;
  2651.         }
  2652.       coff_type.sizes[coff_type.num_sizes] = sizes[i];
  2653.       ++coff_type.num_sizes;
  2654.     }
  2655.  
  2656.   demand_empty_rest_of_line ();
  2657. }
  2658.  
  2659. /* Handle the .type directive, which gives the COFF type of the
  2660.    symbol.  */
  2661.  
  2662. void
  2663. ecoff_directive_type (int ignore ATTRIBUTE_UNUSED)
  2664. {
  2665.   long val;
  2666.   tq_t *tq_ptr;
  2667.   tq_t *tq_shft;
  2668.  
  2669.   if (coff_sym_name == (char *) NULL)
  2670.     {
  2671.       as_warn (_(".type pseudo-op used outside of .def/.endef; ignored"));
  2672.       demand_empty_rest_of_line ();
  2673.       return;
  2674.     }
  2675.  
  2676.   val = get_absolute_expression ();
  2677.  
  2678.   coff_type.orig_type = BTYPE (val);
  2679.   coff_type.basic_type = map_coff_types[coff_type.orig_type];
  2680.  
  2681.   tq_ptr = &coff_type.type_qualifiers[N_TQ];
  2682.   while (val & ~N_BTMASK)
  2683.     {
  2684.       if (tq_ptr == &coff_type.type_qualifiers[0])
  2685.         {
  2686.           /* FIXME: We could handle this by setting the continued bit.
  2687.              There would still be a limit: the .type argument can not
  2688.              be infinite.  */
  2689.           as_warn (_("the type of %s is too complex; it will be simplified"),
  2690.                    coff_sym_name);
  2691.           break;
  2692.         }
  2693.       if (ISPTR (val))
  2694.         *--tq_ptr = tq_Ptr;
  2695.       else if (ISFCN (val))
  2696.         *--tq_ptr = tq_Proc;
  2697.       else if (ISARY (val))
  2698.         *--tq_ptr = tq_Array;
  2699.       else
  2700.         as_fatal (_("Unrecognized .type argument"));
  2701.  
  2702.       val = DECREF (val);
  2703.     }
  2704.  
  2705.   tq_shft = &coff_type.type_qualifiers[0];
  2706.   while (tq_ptr != &coff_type.type_qualifiers[N_TQ])
  2707.     *tq_shft++ = *tq_ptr++;
  2708.  
  2709.   if (tq_shft != &coff_type.type_qualifiers[0] && tq_shft[-1] == tq_Proc)
  2710.     {
  2711.       /* If this is a function, ignore it, so that we don't get two
  2712.          entries (one from the .ent, and one for the .def that
  2713.          precedes it).  Save the type information so that the end
  2714.          block can properly add it after the begin block index.  For
  2715.          MIPS knows what reason, we must strip off the function type
  2716.          at this point.  */
  2717.       coff_is_function = 1;
  2718.       tq_shft[-1] = tq_Nil;
  2719.     }
  2720.  
  2721.   while (tq_shft != &coff_type.type_qualifiers[N_TQ])
  2722.     *tq_shft++ = tq_Nil;
  2723.  
  2724.   demand_empty_rest_of_line ();
  2725. }
  2726.  
  2727. /* Handle the .tag directive, which gives the name of a structure,
  2728.    union or enum.  */
  2729.  
  2730. void
  2731. ecoff_directive_tag (int ignore ATTRIBUTE_UNUSED)
  2732. {
  2733.   char *name;
  2734.   char name_end;
  2735.  
  2736.   if (coff_sym_name == (char *) NULL)
  2737.     {
  2738.       as_warn (_(".tag pseudo-op used outside of .def/.endef; ignored"));
  2739.       demand_empty_rest_of_line ();
  2740.       return;
  2741.     }
  2742.  
  2743.   name = input_line_pointer;
  2744.   name_end = get_symbol_end ();
  2745.  
  2746.   coff_tag = xstrdup (name);
  2747.  
  2748.   *input_line_pointer = name_end;
  2749.  
  2750.   demand_empty_rest_of_line ();
  2751. }
  2752.  
  2753. /* Handle the .val directive, which gives the value of the symbol.  It
  2754.    may be the name of a static or global symbol.  */
  2755.  
  2756. void
  2757. ecoff_directive_val (int ignore ATTRIBUTE_UNUSED)
  2758. {
  2759.   expressionS exp;
  2760.  
  2761.   if (coff_sym_name == (char *) NULL)
  2762.     {
  2763.       as_warn (_(".val pseudo-op used outside of .def/.endef; ignored"));
  2764.       demand_empty_rest_of_line ();
  2765.       return;
  2766.     }
  2767.  
  2768.   expression (&exp);
  2769.   if (exp.X_op != O_constant && exp.X_op != O_symbol)
  2770.     {
  2771.       as_bad (_(".val expression is too complex"));
  2772.       demand_empty_rest_of_line ();
  2773.       return;
  2774.     }
  2775.  
  2776.   if (exp.X_op == O_constant)
  2777.     coff_value = exp.X_add_number;
  2778.   else
  2779.     {
  2780.       coff_sym_value = exp.X_add_symbol;
  2781.       coff_sym_addend = exp.X_add_number;
  2782.     }
  2783.  
  2784.   demand_empty_rest_of_line ();
  2785. }
  2786.  
  2787. /* Handle the .endef directive, which terminates processing of COFF
  2788.    debugging information for a symbol.  */
  2789.  
  2790. void
  2791. ecoff_directive_endef (int ignore ATTRIBUTE_UNUSED)
  2792. {
  2793.   char *name;
  2794.   symint_t indx;
  2795.   localsym_t *sym;
  2796.  
  2797.   demand_empty_rest_of_line ();
  2798.  
  2799.   if (coff_sym_name == (char *) NULL)
  2800.     {
  2801.       as_warn (_(".endef pseudo-op used before .def; ignored"));
  2802.       return;
  2803.     }
  2804.  
  2805.   name = coff_sym_name;
  2806.   coff_sym_name = (char *) NULL;
  2807.  
  2808.   /* If the symbol is a static or external, we have already gotten the
  2809.      appropriate type and class, so make sure we don't override those
  2810.      values.  This is needed because there are some type and classes
  2811.      that are not in COFF, such as short data, etc.  */
  2812.   if (coff_sym_value != (symbolS *) NULL)
  2813.     {
  2814.       coff_symbol_typ = st_Nil;
  2815.       coff_storage_class = sc_Nil;
  2816.     }
  2817.  
  2818.   coff_type.extra_sizes = coff_tag != (char *) NULL;
  2819.   if (coff_type.num_dims > 0)
  2820.     {
  2821.       int diff = coff_type.num_dims - coff_type.num_sizes;
  2822.       int i = coff_type.num_dims - 1;
  2823.       int j;
  2824.  
  2825.       if (coff_type.num_sizes != 1 || diff < 0)
  2826.         {
  2827.           as_warn (_("bad COFF debugging information"));
  2828.           return;
  2829.         }
  2830.  
  2831.       /* If this is an array, make sure the same number of dimensions
  2832.          and sizes were passed, creating extra sizes for multiply
  2833.          dimensioned arrays if not passed.  */
  2834.       coff_type.extra_sizes = 0;
  2835.       if (diff)
  2836.         {
  2837.           j = (sizeof (coff_type.sizes) / sizeof (coff_type.sizes[0])) - 1;
  2838.           while (j >= 0)
  2839.             {
  2840.               coff_type.sizes[j] = (((j - diff) >= 0)
  2841.                                     ? coff_type.sizes[j - diff]
  2842.                                     : 0);
  2843.               j--;
  2844.             }
  2845.  
  2846.           coff_type.num_sizes = i + 1;
  2847.           for (i--; i >= 0; i--)
  2848.             coff_type.sizes[i] = (coff_type.dimensions[i + 1] == 0
  2849.                                   ? 0
  2850.                                   : (coff_type.sizes[i + 1]
  2851.                                      / coff_type.dimensions[i + 1]));
  2852.         }
  2853.     }
  2854.   else if (coff_symbol_typ == st_Member
  2855.            && coff_type.num_sizes - coff_type.extra_sizes == 1)
  2856.     {
  2857.       /* Is this a bitfield?  This is indicated by a structure member
  2858.          having a size field that isn't an array.  */
  2859.       coff_type.bitfield = 1;
  2860.     }
  2861.  
  2862.   /* Except for enumeration members & begin/ending of scopes, put the
  2863.      type word in the aux. symbol table.  */
  2864.   if (coff_symbol_typ == st_Block || coff_symbol_typ == st_End)
  2865.     indx = 0;
  2866.   else if (coff_inside_enumeration)
  2867.     indx = cur_file_ptr->void_type;
  2868.   else
  2869.     {
  2870.       if (coff_type.basic_type == bt_Struct
  2871.           || coff_type.basic_type == bt_Union
  2872.           || coff_type.basic_type == bt_Enum)
  2873.         {
  2874.           if (coff_tag == (char *) NULL)
  2875.             {
  2876.               as_warn (_("no tag specified for %s"), name);
  2877.               return;
  2878.             }
  2879.  
  2880.           coff_type.tag_ptr = get_tag (coff_tag, (localsym_t *) NULL,
  2881.                                        coff_type.basic_type);
  2882.         }
  2883.  
  2884.       if (coff_is_function)
  2885.         {
  2886.           last_func_type_info = coff_type;
  2887.           last_func_sym_value = coff_sym_value;
  2888.           return;
  2889.         }
  2890.  
  2891.       indx = add_aux_sym_tir (&coff_type,
  2892.                               hash_yes,
  2893.                               &cur_file_ptr->thash_head[0]);
  2894.     }
  2895.  
  2896.   /* Do any last minute adjustments that are necessary.  */
  2897.   switch (coff_symbol_typ)
  2898.     {
  2899.     default:
  2900.       break;
  2901.  
  2902.       /* For the beginning of structs, unions, and enumerations, the
  2903.          size info needs to be passed in the value field.  */
  2904.     case st_Block:
  2905.       if (coff_type.num_sizes - coff_type.num_dims - coff_type.extra_sizes
  2906.           != 1)
  2907.         {
  2908.           as_warn (_("bad COFF debugging information"));
  2909.           return;
  2910.         }
  2911.       else
  2912.         coff_value = coff_type.sizes[0];
  2913.  
  2914.       coff_inside_enumeration = (coff_type.orig_type == T_ENUM);
  2915.       break;
  2916.  
  2917.       /* For the end of structs, unions, and enumerations, omit the
  2918.          name which is always ".eos".  This needs to be done last, so
  2919.          that any error reporting above gives the correct name.  */
  2920.     case st_End:
  2921.       free (name);
  2922.       name = (char *) NULL;
  2923.       coff_value = 0;
  2924.       coff_inside_enumeration = 0;
  2925.       break;
  2926.  
  2927.       /* Members of structures and unions that aren't bitfields, need
  2928.          to adjust the value from a byte offset to a bit offset.
  2929.          Members of enumerations do not have the value adjusted, and
  2930.          can be distinguished by indx == indexNil.  For enumerations,
  2931.          update the maximum enumeration value.  */
  2932.     case st_Member:
  2933.       if (! coff_type.bitfield && ! coff_inside_enumeration)
  2934.         coff_value *= 8;
  2935.  
  2936.       break;
  2937.     }
  2938.  
  2939.   /* Add the symbol.  */
  2940.   sym = add_ecoff_symbol (name,
  2941.                           coff_symbol_typ,
  2942.                           coff_storage_class,
  2943.                           coff_sym_value,
  2944.                           coff_sym_addend,
  2945.                           (symint_t) coff_value,
  2946.                           indx);
  2947.  
  2948.   /* deal with struct, union, and enum tags.  */
  2949.   if (coff_symbol_typ == st_Block)
  2950.     {
  2951.       /* Create or update the tag information.  */
  2952.       tag_t *tag_ptr = get_tag (name,
  2953.                                 sym,
  2954.                                 coff_type.basic_type);
  2955.       forward_t **pf;
  2956.  
  2957.       /* Remember any forward references.  */
  2958.       for (pf = &sym->forward_ref;
  2959.            *pf != (forward_t *) NULL;
  2960.            pf = &(*pf)->next)
  2961.         ;
  2962.       *pf = tag_ptr->forward_ref;
  2963.       tag_ptr->forward_ref = (forward_t *) NULL;
  2964.     }
  2965. }
  2966. /* Parse .end directives.  */
  2967.  
  2968. void
  2969. ecoff_directive_end (int ignore ATTRIBUTE_UNUSED)
  2970. {
  2971.   char *name;
  2972.   char name_end;
  2973.   symbolS *ent;
  2974.  
  2975.   if (cur_file_ptr == (efdr_t *) NULL)
  2976.     {
  2977.       as_warn (_(".end directive without a preceding .file directive"));
  2978.       demand_empty_rest_of_line ();
  2979.       return;
  2980.     }
  2981.  
  2982.   if (cur_proc_ptr == (proc_t *) NULL)
  2983.     {
  2984.       as_warn (_(".end directive without a preceding .ent directive"));
  2985.       demand_empty_rest_of_line ();
  2986.       return;
  2987.     }
  2988.  
  2989.   name = input_line_pointer;
  2990.   name_end = get_symbol_end ();
  2991.  
  2992.   if (name == input_line_pointer)
  2993.     {
  2994.       as_warn (_(".end directive has no name"));
  2995.       *input_line_pointer = name_end;
  2996.       demand_empty_rest_of_line ();
  2997.       return;
  2998.     }
  2999.  
  3000.   /* The value is the distance between the .end directive and the
  3001.      corresponding symbol.  We create a fake symbol to hold the
  3002.      current location, and put in the offset when we write out the
  3003.      symbol.  */
  3004.   ent = symbol_find (name);
  3005.   if (ent == (symbolS *) NULL)
  3006.     as_warn (_(".end directive names unknown symbol"));
  3007.   else
  3008.     (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text,
  3009.                              symbol_new ("L0\001", now_seg,
  3010.                                          (valueT) frag_now_fix (),
  3011.                                          frag_now),
  3012.                              (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  3013.  
  3014.   cur_proc_ptr = (proc_t *) NULL;
  3015.  
  3016.   *input_line_pointer = name_end;
  3017.   demand_empty_rest_of_line ();
  3018. }
  3019. /* Parse .ent directives.  */
  3020.  
  3021. void
  3022. ecoff_directive_ent (int ignore ATTRIBUTE_UNUSED)
  3023. {
  3024.   char *name;
  3025.   char name_end;
  3026.  
  3027.   if (cur_file_ptr == (efdr_t *) NULL)
  3028.     add_file ((const char *) NULL, 0, 1);
  3029.  
  3030.   if (cur_proc_ptr != (proc_t *) NULL)
  3031.     {
  3032.       as_warn (_("second .ent directive found before .end directive"));
  3033.       demand_empty_rest_of_line ();
  3034.       return;
  3035.     }
  3036.  
  3037.   name = input_line_pointer;
  3038.   name_end = get_symbol_end ();
  3039.  
  3040.   if (name == input_line_pointer)
  3041.     {
  3042.       as_warn (_(".ent directive has no name"));
  3043.       *input_line_pointer = name_end;
  3044.       demand_empty_rest_of_line ();
  3045.       return;
  3046.     }
  3047.  
  3048.   add_procedure (name);
  3049.  
  3050.   *input_line_pointer = name_end;
  3051.  
  3052.   /* The .ent directive is sometimes followed by a number.  I'm not
  3053.      really sure what the number means.  I don't see any way to store
  3054.      the information in the PDR.  The Irix 4 assembler seems to ignore
  3055.      the information.  */
  3056.   SKIP_WHITESPACE ();
  3057.   if (*input_line_pointer == ',')
  3058.     {
  3059.       ++input_line_pointer;
  3060.       SKIP_WHITESPACE ();
  3061.     }
  3062.   if (ISDIGIT (*input_line_pointer)
  3063.       || *input_line_pointer == '-')
  3064.     (void) get_absolute_expression ();
  3065.  
  3066.   demand_empty_rest_of_line ();
  3067. }
  3068. /* Parse .extern directives.  */
  3069.  
  3070. void
  3071. ecoff_directive_extern (int ignore ATTRIBUTE_UNUSED)
  3072. {
  3073.   char *name;
  3074.   int c;
  3075.   symbolS *symbolp;
  3076.   valueT size;
  3077.  
  3078.   name = input_line_pointer;
  3079.   c = get_symbol_end ();
  3080.   symbolp = symbol_find_or_make (name);
  3081.   *input_line_pointer = c;
  3082.  
  3083.   S_SET_EXTERNAL (symbolp);
  3084.  
  3085.   if (*input_line_pointer == ',')
  3086.     ++input_line_pointer;
  3087.   size = get_absolute_expression ();
  3088.  
  3089.   symbol_get_obj (symbolp)->ecoff_extern_size = size;
  3090. }
  3091. /* Parse .file directives.  */
  3092.  
  3093. void
  3094. ecoff_directive_file (int ignore ATTRIBUTE_UNUSED)
  3095. {
  3096.   int indx;
  3097.   char *name;
  3098.   int len;
  3099.  
  3100.   if (cur_proc_ptr != (proc_t *) NULL)
  3101.     {
  3102.       as_warn (_("no way to handle .file within .ent/.end section"));
  3103.       demand_empty_rest_of_line ();
  3104.       return;
  3105.     }
  3106.  
  3107.   indx = (int) get_absolute_expression ();
  3108.  
  3109.   /* FIXME: we don't have to save the name here.  */
  3110.   name = demand_copy_C_string (&len);
  3111.  
  3112.   add_file (name, indx - 1, 0);
  3113.  
  3114.   demand_empty_rest_of_line ();
  3115. }
  3116. /* Parse .fmask directives.  */
  3117.  
  3118. void
  3119. ecoff_directive_fmask (int ignore ATTRIBUTE_UNUSED)
  3120. {
  3121.   long val;
  3122.  
  3123.   if (cur_proc_ptr == (proc_t *) NULL)
  3124.     {
  3125.       as_warn (_(".fmask outside of .ent"));
  3126.       demand_empty_rest_of_line ();
  3127.       return;
  3128.     }
  3129.  
  3130.   if (get_absolute_expression_and_terminator (&val) != ',')
  3131.     {
  3132.       as_warn (_("bad .fmask directive"));
  3133.       --input_line_pointer;
  3134.       demand_empty_rest_of_line ();
  3135.       return;
  3136.     }
  3137.  
  3138.   cur_proc_ptr->pdr.fregmask = val;
  3139.   cur_proc_ptr->pdr.fregoffset = get_absolute_expression ();
  3140.  
  3141.   demand_empty_rest_of_line ();
  3142. }
  3143. /* Parse .frame directives.  */
  3144.  
  3145. void
  3146. ecoff_directive_frame (int ignore ATTRIBUTE_UNUSED)
  3147. {
  3148.   long val;
  3149.  
  3150.   if (cur_proc_ptr == (proc_t *) NULL)
  3151.     {
  3152.       as_warn (_(".frame outside of .ent"));
  3153.       demand_empty_rest_of_line ();
  3154.       return;
  3155.     }
  3156.  
  3157.   cur_proc_ptr->pdr.framereg = tc_get_register (1);
  3158.  
  3159.   SKIP_WHITESPACE ();
  3160.   if (*input_line_pointer++ != ','
  3161.       || get_absolute_expression_and_terminator (&val) != ',')
  3162.     {
  3163.       as_warn (_("bad .frame directive"));
  3164.       --input_line_pointer;
  3165.       demand_empty_rest_of_line ();
  3166.       return;
  3167.     }
  3168.  
  3169.   cur_proc_ptr->pdr.frameoffset = val;
  3170.  
  3171.   cur_proc_ptr->pdr.pcreg = tc_get_register (0);
  3172.  
  3173.   /* Alpha-OSF1 adds "the offset of saved $a0 from $sp", according to
  3174.      Sandro.  I don't yet know where this value should be stored, if
  3175.      anywhere.  Don't call demand_empty_rest_of_line ().  */
  3176.   s_ignore (42);
  3177. }
  3178. /* Parse .mask directives.  */
  3179.  
  3180. void
  3181. ecoff_directive_mask (int ignore ATTRIBUTE_UNUSED)
  3182. {
  3183.   long val;
  3184.  
  3185.   if (cur_proc_ptr == (proc_t *) NULL)
  3186.     {
  3187.       as_warn (_(".mask outside of .ent"));
  3188.       demand_empty_rest_of_line ();
  3189.       return;
  3190.     }
  3191.  
  3192.   if (get_absolute_expression_and_terminator (&val) != ',')
  3193.     {
  3194.       as_warn (_("bad .mask directive"));
  3195.       --input_line_pointer;
  3196.       demand_empty_rest_of_line ();
  3197.       return;
  3198.     }
  3199.  
  3200.   cur_proc_ptr->pdr.regmask = val;
  3201.   cur_proc_ptr->pdr.regoffset = get_absolute_expression ();
  3202.  
  3203.   demand_empty_rest_of_line ();
  3204. }
  3205. /* Parse .loc directives.  */
  3206.  
  3207. void
  3208. ecoff_directive_loc (int ignore ATTRIBUTE_UNUSED)
  3209. {
  3210.   lineno_list_t *list;
  3211.   symint_t lineno;
  3212.  
  3213.   if (cur_file_ptr == (efdr_t *) NULL)
  3214.     {
  3215.       as_warn (_(".loc before .file"));
  3216.       demand_empty_rest_of_line ();
  3217.       return;
  3218.     }
  3219.  
  3220.   if (now_seg != text_section)
  3221.     {
  3222.       as_warn (_(".loc outside of .text"));
  3223.       demand_empty_rest_of_line ();
  3224.       return;
  3225.     }
  3226.  
  3227.   /* Skip the file number.  */
  3228.   SKIP_WHITESPACE ();
  3229.   get_absolute_expression ();
  3230.   SKIP_WHITESPACE ();
  3231.  
  3232.   lineno = get_absolute_expression ();
  3233.  
  3234. #ifndef NO_LISTING
  3235.   if (listing)
  3236.     listing_source_line (lineno);
  3237. #endif
  3238.  
  3239.   /* If we're building stabs, then output a special label rather than
  3240.      ECOFF line number info.  */
  3241.   if (stabs_seen)
  3242.     {
  3243.       (void) add_ecoff_symbol ((char *) NULL, st_Label, sc_Text,
  3244.                                symbol_new ("L0\001", now_seg,
  3245.                                            (valueT) frag_now_fix (),
  3246.                                            frag_now),
  3247.                                (bfd_vma) 0, 0, lineno);
  3248.       return;
  3249.     }
  3250.  
  3251.   list = allocate_lineno_list ();
  3252.  
  3253.   list->next = (lineno_list_t *) NULL;
  3254.   list->file = cur_file_ptr;
  3255.   list->proc = cur_proc_ptr;
  3256.   list->frag = frag_now;
  3257.   list->paddr = frag_now_fix ();
  3258.   list->lineno = lineno;
  3259.  
  3260.   /* We don't want to merge files which have line numbers.  */
  3261.   cur_file_ptr->fdr.fMerge = 0;
  3262.  
  3263.   /* A .loc directive will sometimes appear before a .ent directive,
  3264.      which means that cur_proc_ptr will be NULL here.  Arrange to
  3265.      patch this up.  */
  3266.   if (cur_proc_ptr == (proc_t *) NULL)
  3267.     {
  3268.       lineno_list_t **pl;
  3269.  
  3270.       pl = &noproc_lineno;
  3271.       while (*pl != (lineno_list_t *) NULL)
  3272.         pl = &(*pl)->next;
  3273.       *pl = list;
  3274.     }
  3275.   else
  3276.     {
  3277.       last_lineno = list;
  3278.       *last_lineno_ptr = list;
  3279.       last_lineno_ptr = &list->next;
  3280.     }
  3281. }
  3282.  
  3283. /* The MIPS assembler sometimes inserts nop instructions in the
  3284.    instruction stream.  When this happens, we must patch up the .loc
  3285.    information so that it points to the instruction after the nop.  */
  3286.  
  3287. void
  3288. ecoff_fix_loc (fragS *old_frag, unsigned long old_frag_offset)
  3289. {
  3290.   if (last_lineno != NULL
  3291.       && last_lineno->frag == old_frag
  3292.       && last_lineno->paddr == old_frag_offset)
  3293.     {
  3294.       last_lineno->frag = frag_now;
  3295.       last_lineno->paddr = frag_now_fix ();
  3296.     }
  3297. }
  3298. /* Make sure the @stabs symbol is emitted.  */
  3299.  
  3300. static void
  3301. mark_stabs (int ignore ATTRIBUTE_UNUSED)
  3302. {
  3303.   if (! stabs_seen)
  3304.     {
  3305.       /* Add a dummy @stabs dymbol.  */
  3306.       stabs_seen = 1;
  3307.       (void) add_ecoff_symbol (stabs_symbol, st_Nil, sc_Info,
  3308.                                (symbolS *) NULL,
  3309.                                (bfd_vma) 0, (symint_t) -1,
  3310.                                ECOFF_MARK_STAB (0));
  3311.     }
  3312. }
  3313. /* Parse .weakext directives.  */
  3314. #ifndef TC_MIPS
  3315. /* For TC_MIPS use the version in tc-mips.c.  */
  3316. void
  3317. ecoff_directive_weakext (int ignore ATTRIBUTE_UNUSED)
  3318. {
  3319.   char *name;
  3320.   int c;
  3321.   symbolS *symbolP;
  3322.   expressionS exp;
  3323.  
  3324.   name = input_line_pointer;
  3325.   c = get_symbol_end ();
  3326.   symbolP = symbol_find_or_make (name);
  3327.   *input_line_pointer = c;
  3328.  
  3329.   SKIP_WHITESPACE ();
  3330.  
  3331.   if (*input_line_pointer == ',')
  3332.     {
  3333.       if (S_IS_DEFINED (symbolP))
  3334.         {
  3335.           as_bad (_("symbol `%s' is already defined"),
  3336.                   S_GET_NAME (symbolP));
  3337.           ignore_rest_of_line ();
  3338.           return;
  3339.         }
  3340.  
  3341.       ++input_line_pointer;
  3342.       SKIP_WHITESPACE ();
  3343.       if (! is_end_of_line[(unsigned char) *input_line_pointer])
  3344.         {
  3345.           expression (&exp);
  3346.           if (exp.X_op != O_symbol)
  3347.             {
  3348.               as_bad (_("bad .weakext directive"));
  3349.               ignore_rest_of_line ();
  3350.               return;
  3351.             }
  3352.           symbol_set_value_expression (symbolP, &exp);
  3353.         }
  3354.     }
  3355.  
  3356.   S_SET_WEAK (symbolP);
  3357.  
  3358.   demand_empty_rest_of_line ();
  3359. }
  3360. #endif /* not TC_MIPS */
  3361. /* Handle .stabs directives.  The actual parsing routine is done by a
  3362.    generic routine.  This routine is called via OBJ_PROCESS_STAB.
  3363.    When this is called, input_line_pointer will be pointing at the
  3364.    value field of the stab.
  3365.  
  3366.    .stabs directives have five fields:
  3367.         "string"        a string, encoding the type information.
  3368.         code            a numeric code, defined in <stab.h>
  3369.         0               a zero
  3370.         desc            a zero or line number
  3371.         value           a numeric value or an address.
  3372.  
  3373.     If the value is relocatable, we transform this into:
  3374.         iss             points as an index into string space
  3375.         value           value from lookup of the name
  3376.         st              st from lookup of the name
  3377.         sc              sc from lookup of the name
  3378.         index           code|CODE_MASK
  3379.  
  3380.     If the value is not relocatable, we transform this into:
  3381.         iss             points as an index into string space
  3382.         value           value
  3383.         st              st_Nil
  3384.         sc              sc_Nil
  3385.         index           code|CODE_MASK
  3386.  
  3387.     .stabn directives have four fields (string is null):
  3388.         code            a numeric code, defined in <stab.h>
  3389.         0               a zero
  3390.         desc            a zero or a line number
  3391.         value           a numeric value or an address.  */
  3392.  
  3393. void
  3394. ecoff_stab (segT sec ATTRIBUTE_UNUSED,
  3395.             int what,
  3396.             const char *string,
  3397.             int type,
  3398.             int other,
  3399.             int desc)
  3400. {
  3401.   efdr_t *save_file_ptr = cur_file_ptr;
  3402.   symbolS *sym;
  3403.   symint_t value;
  3404.   bfd_vma addend;
  3405.   st_t st;
  3406.   sc_t sc;
  3407.   symint_t indx;
  3408.   localsym_t *hold = NULL;
  3409.  
  3410.   ecoff_debugging_seen = 1;
  3411.  
  3412.   /* We don't handle .stabd.  */
  3413.   if (what != 's' && what != 'n')
  3414.     {
  3415.       as_bad (_(".stab%c is not supported"), what);
  3416.       return;
  3417.     }
  3418.  
  3419.   /* A .stabn uses a null name, not an empty string.  */
  3420.   if (what == 'n')
  3421.     string = NULL;
  3422.  
  3423.   /* We ignore the other field.  */
  3424.   if (other != 0)
  3425.     as_warn (_(".stab%c: ignoring non-zero other field"), what);
  3426.  
  3427.   /* Make sure we have a current file.  */
  3428.   if (cur_file_ptr == (efdr_t *) NULL)
  3429.     {
  3430.       add_file ((const char *) NULL, 0, 1);
  3431.       save_file_ptr = cur_file_ptr;
  3432.     }
  3433.  
  3434.   /* For stabs in ECOFF, the first symbol must be @stabs.  This is a
  3435.      signal to gdb.  */
  3436.   if (stabs_seen == 0)
  3437.     mark_stabs (0);
  3438.  
  3439.   /* Line number stabs are handled differently, since they have two
  3440.      values, the line number and the address of the label.  We use the
  3441.      index field (aka desc) to hold the line number, and the value
  3442.      field to hold the address.  The symbol type is st_Label, which
  3443.      should be different from the other stabs, so that gdb can
  3444.      recognize it.  */
  3445.   if (type == N_SLINE)
  3446.     {
  3447.       SYMR dummy_symr;
  3448.       char *name;
  3449.       char name_end;
  3450.  
  3451. #ifndef NO_LISTING
  3452.       if (listing)
  3453.         listing_source_line ((unsigned int) desc);
  3454. #endif
  3455.  
  3456.       dummy_symr.index = desc;
  3457.       if (dummy_symr.index != desc)
  3458.         {
  3459.           as_warn (_("line number (%d) for .stab%c directive cannot fit in index field (20 bits)"),
  3460.                    desc, what);
  3461.           return;
  3462.         }
  3463.  
  3464.       name = input_line_pointer;
  3465.       name_end = get_symbol_end ();
  3466.  
  3467.       sym = symbol_find_or_make (name);
  3468.       *input_line_pointer = name_end;
  3469.  
  3470.       value = 0;
  3471.       addend = 0;
  3472.       st = st_Label;
  3473.       sc = sc_Text;
  3474.       indx = desc;
  3475.     }
  3476.   else
  3477.     {
  3478. #ifndef NO_LISTING
  3479.       if (listing && (type == N_SO || type == N_SOL))
  3480.         listing_source_file (string);
  3481. #endif
  3482.  
  3483.       if (ISDIGIT (*input_line_pointer)
  3484.           || *input_line_pointer == '-'
  3485.           || *input_line_pointer == '+')
  3486.         {
  3487.           st = st_Nil;
  3488.           sc = sc_Nil;
  3489.           sym = (symbolS *) NULL;
  3490.           value = get_absolute_expression ();
  3491.           addend = 0;
  3492.         }
  3493.       else if (! is_name_beginner ((unsigned char) *input_line_pointer))
  3494.         {
  3495.           as_warn (_("illegal .stab%c directive, bad character"), what);
  3496.           return;
  3497.         }
  3498.       else
  3499.         {
  3500.           expressionS exp;
  3501.  
  3502.           sc = sc_Nil;
  3503.           st = st_Nil;
  3504.  
  3505.           expression (&exp);
  3506.           if (exp.X_op == O_constant)
  3507.             {
  3508.               sym = NULL;
  3509.               value = exp.X_add_number;
  3510.               addend = 0;
  3511.             }
  3512.           else if (exp.X_op == O_symbol)
  3513.             {
  3514.               sym = exp.X_add_symbol;
  3515.               value = 0;
  3516.               addend = exp.X_add_number;
  3517.             }
  3518.           else
  3519.             {
  3520.               sym = make_expr_symbol (&exp);
  3521.               value = 0;
  3522.               addend = 0;
  3523.             }
  3524.         }
  3525.  
  3526.       indx = ECOFF_MARK_STAB (type);
  3527.     }
  3528.  
  3529.   /* Don't store the stabs symbol we are creating as the type of the
  3530.      ECOFF symbol.  We want to compute the type of the ECOFF symbol
  3531.      independently.  */
  3532.   if (sym != (symbolS *) NULL)
  3533.     hold = symbol_get_obj (sym)->ecoff_symbol;
  3534.  
  3535.   (void) add_ecoff_symbol (string, st, sc, sym, addend, value, indx);
  3536.  
  3537.   if (sym != (symbolS *) NULL)
  3538.     symbol_get_obj (sym)->ecoff_symbol = hold;
  3539.  
  3540.   /* Restore normal file type.  */
  3541.   cur_file_ptr = save_file_ptr;
  3542. }
  3543. /* Frob an ECOFF symbol.  Small common symbols go into a special
  3544.    .scommon section rather than bfd_com_section.  */
  3545.  
  3546. void
  3547. ecoff_frob_symbol (symbolS *sym)
  3548. {
  3549.   if (S_IS_COMMON (sym)
  3550.       && S_GET_VALUE (sym) > 0
  3551.       && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput))
  3552.     {
  3553.       static asection scom_section;
  3554.       static asymbol scom_symbol;
  3555.  
  3556.       /* We must construct a fake section similar to bfd_com_section
  3557.          but with the name .scommon.  */
  3558.       if (scom_section.name == NULL)
  3559.         {
  3560.           scom_section = *bfd_com_section_ptr;
  3561.           scom_section.name = ".scommon";
  3562.           scom_section.output_section = &scom_section;
  3563.           scom_section.symbol = &scom_symbol;
  3564.           scom_section.symbol_ptr_ptr = &scom_section.symbol;
  3565.           scom_symbol = *bfd_com_section_ptr->symbol;
  3566.           scom_symbol.name = ".scommon";
  3567.           scom_symbol.section = &scom_section;
  3568.         }
  3569.       S_SET_SEGMENT (sym, &scom_section);
  3570.     }
  3571.  
  3572.   /* Double check weak symbols.  */
  3573.   if (S_IS_WEAK (sym))
  3574.     {
  3575.       if (S_IS_COMMON (sym))
  3576.         as_bad (_("symbol `%s' can not be both weak and common"),
  3577.                 S_GET_NAME (sym));
  3578.     }
  3579. }
  3580. /* Add bytes to the symbolic information buffer.  */
  3581.  
  3582. static char *
  3583. ecoff_add_bytes (char **buf,
  3584.                  char **bufend,
  3585.                  char *bufptr,
  3586.                  unsigned long need)
  3587. {
  3588.   unsigned long at;
  3589.   unsigned long want;
  3590.  
  3591.   at = bufptr - *buf;
  3592.   need -= *bufend - bufptr;
  3593.   if (need < PAGE_SIZE)
  3594.     need = PAGE_SIZE;
  3595.   want = (*bufend - *buf) + need;
  3596.   *buf = (char *) xrealloc (*buf, want);
  3597.   *bufend = *buf + want;
  3598.   return *buf + at;
  3599. }
  3600.  
  3601. /* Adjust the symbolic information buffer to the alignment required
  3602.    for the ECOFF target debugging information.  */
  3603.  
  3604. static unsigned long
  3605. ecoff_padding_adjust (const struct ecoff_debug_swap *backend,
  3606.                       char **buf,
  3607.                       char **bufend,
  3608.                       unsigned long offset,
  3609.                       char **bufptrptr)
  3610. {
  3611.   bfd_size_type align;
  3612.  
  3613.   align = backend->debug_align;
  3614.   if ((offset & (align - 1)) != 0)
  3615.     {
  3616.       unsigned long add;
  3617.  
  3618.       add = align - (offset & (align - 1));
  3619.       if ((unsigned long) (*bufend - (*buf + offset)) < add)
  3620.         (void) ecoff_add_bytes (buf, bufend, *buf + offset, add);
  3621.       memset (*buf + offset, 0, add);
  3622.       offset += add;
  3623.       if (bufptrptr != (char **) NULL)
  3624.         *bufptrptr = *buf + offset;
  3625.     }
  3626.  
  3627.   return offset;
  3628. }
  3629.  
  3630. /* Build the line number information.  */
  3631.  
  3632. static unsigned long
  3633. ecoff_build_lineno (const struct ecoff_debug_swap *backend,
  3634.                     char **buf,
  3635.                     char **bufend,
  3636.                     unsigned long offset,
  3637.                     long *linecntptr)
  3638. {
  3639.   char *bufptr;
  3640.   register lineno_list_t *l;
  3641.   lineno_list_t *last;
  3642.   efdr_t *file;
  3643.   proc_t *proc;
  3644.   unsigned long c;
  3645.   long iline;
  3646.   long totcount;
  3647.   lineno_list_t first;
  3648.   lineno_list_t *local_first_lineno = first_lineno;
  3649.  
  3650.   if (linecntptr != (long *) NULL)
  3651.     *linecntptr = 0;
  3652.  
  3653.   bufptr = *buf + offset;
  3654.  
  3655.   file = (efdr_t *) NULL;
  3656.   proc = (proc_t *) NULL;
  3657.   last = (lineno_list_t *) NULL;
  3658.   c = offset;
  3659.   iline = 0;
  3660.   totcount = 0;
  3661.  
  3662.   /* FIXME?  Now that MIPS embedded-PIC is gone, it may be safe to
  3663.      remove this code.  */
  3664.   /* For some reason the address of the first procedure is ignored
  3665.      when reading line numbers.  This doesn't matter if the address of
  3666.      the first procedure is 0, but when gcc is generating MIPS
  3667.      embedded PIC code, it will put strings in the .text section
  3668.      before the first procedure.  We cope by inserting a dummy line if
  3669.      the address of the first procedure is not 0.  Hopefully this
  3670.      won't screw things up too badly.
  3671.  
  3672.      Don't do this for ECOFF assembly source line numbers.  They work
  3673.      without this extra attention.  */
  3674.   if (debug_type != DEBUG_ECOFF
  3675.       && first_proc_ptr != (proc_t *) NULL
  3676.       && local_first_lineno != (lineno_list_t *) NULL
  3677.       && ((S_GET_VALUE (first_proc_ptr->sym->as_sym)
  3678.            + bfd_get_section_vma (stdoutput,
  3679.                                   S_GET_SEGMENT (first_proc_ptr->sym->as_sym)))
  3680.           != 0))
  3681.     {
  3682.       first.file = local_first_lineno->file;
  3683.       first.proc = local_first_lineno->proc;
  3684.       first.frag = &zero_address_frag;
  3685.       first.paddr = 0;
  3686.       first.lineno = 0;
  3687.  
  3688.       first.next = local_first_lineno;
  3689.       local_first_lineno = &first;
  3690.     }
  3691.  
  3692.   for (l = local_first_lineno; l != (lineno_list_t *) NULL; l = l->next)
  3693.     {
  3694.       long count;
  3695.       long delta;
  3696.  
  3697.       /* Get the offset to the memory address of the next line number
  3698.          (in words).  Do this first, so that we can skip ahead to the
  3699.          next useful line number entry.  */
  3700.       if (l->next == (lineno_list_t *) NULL)
  3701.         {
  3702.           /* We want a count of zero, but it will be decremented
  3703.              before it is used.  */
  3704.           count = 1;
  3705.         }
  3706.       else if (l->next->frag->fr_address + l->next->paddr
  3707.                > l->frag->fr_address + l->paddr)
  3708.         {
  3709.           count = ((l->next->frag->fr_address + l->next->paddr
  3710.                     - (l->frag->fr_address + l->paddr))
  3711.                    >> 2);
  3712.         }
  3713.       else
  3714.         {
  3715.           /* Don't change last, so we still get the right delta.  */
  3716.           continue;
  3717.         }
  3718.  
  3719.       if (l->file != file || l->proc != proc)
  3720.         {
  3721.           if (l->proc != proc && proc != (proc_t *) NULL)
  3722.             proc->pdr.lnHigh = last->lineno;
  3723.           if (l->file != file && file != (efdr_t *) NULL)
  3724.             {
  3725.               file->fdr.cbLine = c - file->fdr.cbLineOffset;
  3726.               file->fdr.cline = totcount + count;
  3727.               if (linecntptr != (long *) NULL)
  3728.                 *linecntptr += totcount + count;
  3729.               totcount = 0;
  3730.             }
  3731.  
  3732.           if (l->file != file)
  3733.             {
  3734.               efdr_t *last_file = file;
  3735.  
  3736.               file = l->file;
  3737.               if (last_file != (efdr_t *) NULL)
  3738.                 file->fdr.ilineBase
  3739.                   = last_file->fdr.ilineBase + last_file->fdr.cline;
  3740.               else
  3741.                 file->fdr.ilineBase = 0;
  3742.               file->fdr.cbLineOffset = c;
  3743.             }
  3744.           if (l->proc != proc)
  3745.             {
  3746.               proc = l->proc;
  3747.               if (proc != (proc_t *) NULL)
  3748.                 {
  3749.                   proc->pdr.lnLow = l->lineno;
  3750.                   proc->pdr.cbLineOffset = c - file->fdr.cbLineOffset;
  3751.                   proc->pdr.iline = totcount;
  3752.                 }
  3753.             }
  3754.  
  3755.           last = (lineno_list_t *) NULL;
  3756.         }
  3757.  
  3758.       totcount += count;
  3759.  
  3760.       /* Get the offset to this line number.  */
  3761.       if (last == (lineno_list_t *) NULL)
  3762.         delta = 0;
  3763.       else
  3764.         delta = l->lineno - last->lineno;
  3765.  
  3766.       /* Put in the offset to this line number.  */
  3767.       while (delta != 0)
  3768.         {
  3769.           int setcount;
  3770.  
  3771.           /* 1 is added to each count read.  */
  3772.           --count;
  3773.           /* We can only adjust the word count by up to 15 words at a
  3774.              time.  */
  3775.           if (count <= 0x0f)
  3776.             {
  3777.               setcount = count;
  3778.               count = 0;
  3779.             }
  3780.           else
  3781.             {
  3782.               setcount = 0x0f;
  3783.               count -= 0x0f;
  3784.             }
  3785.           if (delta >= -7 && delta <= 7)
  3786.             {
  3787.               if (bufptr >= *bufend)
  3788.                 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
  3789.               *bufptr++ = setcount + (delta << 4);
  3790.               delta = 0;
  3791.               ++c;
  3792.             }
  3793.           else
  3794.             {
  3795.               int set;
  3796.  
  3797.               if (*bufend - bufptr < 3)
  3798.                 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 3);
  3799.               *bufptr++ = setcount + (8 << 4);
  3800.               if (delta < -0x8000)
  3801.                 {
  3802.                   set = -0x8000;
  3803.                   delta += 0x8000;
  3804.                 }
  3805.               else if (delta > 0x7fff)
  3806.                 {
  3807.                   set = 0x7fff;
  3808.                   delta -= 0x7fff;
  3809.                 }
  3810.               else
  3811.                 {
  3812.                   set = delta;
  3813.                   delta = 0;
  3814.                 }
  3815.               *bufptr++ = set >> 8;
  3816.               *bufptr++ = set & 0xffff;
  3817.               c += 3;
  3818.             }
  3819.         }
  3820.  
  3821.       /* Finish adjusting the count.  */
  3822.       while (count > 0)
  3823.         {
  3824.           if (bufptr >= *bufend)
  3825.             bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
  3826.           /* 1 is added to each count read.  */
  3827.           --count;
  3828.           if (count > 0x0f)
  3829.             {
  3830.               *bufptr++ = 0x0f;
  3831.               count -= 0x0f;
  3832.             }
  3833.           else
  3834.             {
  3835.               *bufptr++ = count;
  3836.               count = 0;
  3837.             }
  3838.           ++c;
  3839.         }
  3840.  
  3841.       ++iline;
  3842.       last = l;
  3843.     }
  3844.  
  3845.   if (proc != (proc_t *) NULL)
  3846.     proc->pdr.lnHigh = last->lineno;
  3847.   if (file != (efdr_t *) NULL)
  3848.     {
  3849.       file->fdr.cbLine = c - file->fdr.cbLineOffset;
  3850.       file->fdr.cline = totcount;
  3851.     }
  3852.  
  3853.   if (linecntptr != (long *) NULL)
  3854.     *linecntptr += totcount;
  3855.  
  3856.   c = ecoff_padding_adjust (backend, buf, bufend, c, &bufptr);
  3857.  
  3858.   return c;
  3859. }
  3860.  
  3861. /* Build and swap out the symbols.  */
  3862.  
  3863. static unsigned long
  3864. ecoff_build_symbols (const struct ecoff_debug_swap *backend,
  3865.                      char **buf,
  3866.                      char **bufend,
  3867.                      unsigned long offset)
  3868. {
  3869.   const bfd_size_type external_sym_size = backend->external_sym_size;
  3870.   void (* const swap_sym_out) (bfd *, const SYMR *, void *)
  3871.     = backend->swap_sym_out;
  3872.   char *sym_out;
  3873.   long isym;
  3874.   vlinks_t *file_link;
  3875.  
  3876.   sym_out = *buf + offset;
  3877.  
  3878.   isym = 0;
  3879.  
  3880.   /* The symbols are stored by file.  */
  3881.   for (file_link = file_desc.first;
  3882.        file_link != (vlinks_t *) NULL;
  3883.        file_link = file_link->next)
  3884.     {
  3885.       int ifilesym;
  3886.       int fil_cnt;
  3887.       efdr_t *fil_ptr;
  3888.       efdr_t *fil_end;
  3889.  
  3890.       if (file_link->next == (vlinks_t *) NULL)
  3891.         fil_cnt = file_desc.objects_last_page;
  3892.       else
  3893.         fil_cnt = file_desc.objects_per_page;
  3894.       fil_ptr = file_link->datum->file;
  3895.       fil_end = fil_ptr + fil_cnt;
  3896.       for (; fil_ptr < fil_end; fil_ptr++)
  3897.         {
  3898.           vlinks_t *sym_link;
  3899.  
  3900.           fil_ptr->fdr.isymBase = isym;
  3901.           ifilesym = isym;
  3902.           for (sym_link = fil_ptr->symbols.first;
  3903.                sym_link != (vlinks_t *) NULL;
  3904.                sym_link = sym_link->next)
  3905.             {
  3906.               int sym_cnt;
  3907.               localsym_t *sym_ptr;
  3908.               localsym_t *sym_end;
  3909.  
  3910.               if (sym_link->next == (vlinks_t *) NULL)
  3911.                 sym_cnt = fil_ptr->symbols.objects_last_page;
  3912.               else
  3913.                 sym_cnt = fil_ptr->symbols.objects_per_page;
  3914.               sym_ptr = sym_link->datum->sym;
  3915.               sym_end = sym_ptr + sym_cnt;
  3916.               for (; sym_ptr < sym_end; sym_ptr++)
  3917.                 {
  3918.                   int local;
  3919.                   symbolS *as_sym;
  3920.                   forward_t *f;
  3921.  
  3922.                   know (sym_ptr->file_ptr == fil_ptr);
  3923.  
  3924.                   /* If there is no associated gas symbol, then this
  3925.                      is a pure debugging symbol.  We have already
  3926.                      added the name (if any) to fil_ptr->strings.
  3927.                      Otherwise we must decide whether this is an
  3928.                      external or a local symbol (actually, it may be
  3929.                      both if the local provides additional debugging
  3930.                      information for the external).  */
  3931.                   local = 1;
  3932.                   as_sym = sym_ptr->as_sym;
  3933.                   if (as_sym != (symbolS *) NULL)
  3934.                     {
  3935.                       symint_t indx;
  3936.  
  3937.                       /* The value of a block start symbol is the
  3938.                          offset from the start of the procedure.  For
  3939.                          other symbols we just use the gas value (but
  3940.                          we must offset it by the vma of the section,
  3941.                          just as BFD does, because BFD will not see
  3942.                          this value).  */
  3943.                       if (sym_ptr->ecoff_sym.asym.st == (int) st_Block
  3944.                           && sym_ptr->ecoff_sym.asym.sc == (int) sc_Text)
  3945.                         {
  3946.                           symbolS *begin_sym;
  3947.  
  3948.                           know (sym_ptr->proc_ptr != (proc_t *) NULL);
  3949.                           begin_sym = sym_ptr->proc_ptr->sym->as_sym;
  3950.                           if (S_GET_SEGMENT (as_sym)
  3951.                               != S_GET_SEGMENT (begin_sym))
  3952.                             as_warn (_(".begin/.bend in different segments"));
  3953.                           sym_ptr->ecoff_sym.asym.value =
  3954.                             S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
  3955.                         }
  3956.                       else
  3957.                         sym_ptr->ecoff_sym.asym.value =
  3958.                           (S_GET_VALUE (as_sym)
  3959.                            + bfd_get_section_vma (stdoutput,
  3960.                                                   S_GET_SEGMENT (as_sym))
  3961.                            + sym_ptr->addend);
  3962.  
  3963.                       sym_ptr->ecoff_sym.weakext = S_IS_WEAK (as_sym);
  3964.  
  3965.                       /* Set st_Proc to st_StaticProc for local
  3966.                          functions.  */
  3967.                       if (sym_ptr->ecoff_sym.asym.st == st_Proc
  3968.                           && S_IS_DEFINED (as_sym)
  3969.                           && ! S_IS_EXTERNAL (as_sym)
  3970.                           && ! S_IS_WEAK (as_sym))
  3971.                         sym_ptr->ecoff_sym.asym.st = st_StaticProc;
  3972.  
  3973.                       /* Get the type and storage class based on where
  3974.                          the symbol actually wound up.  Traditionally,
  3975.                          N_LBRAC and N_RBRAC are *not* relocated.  */
  3976.                       indx = sym_ptr->ecoff_sym.asym.index;
  3977.                       if (sym_ptr->ecoff_sym.asym.st == st_Nil
  3978.                           && sym_ptr->ecoff_sym.asym.sc == sc_Nil
  3979.                           && (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
  3980.                               || ((ECOFF_UNMARK_STAB (indx) != N_LBRAC)
  3981.                                   && (ECOFF_UNMARK_STAB (indx) != N_RBRAC))))
  3982.                         {
  3983.                           segT seg;
  3984.                           const char *segname;
  3985.                           st_t st;
  3986.                           sc_t sc;
  3987.  
  3988.                           seg = S_GET_SEGMENT (as_sym);
  3989.                           segname = segment_name (seg);
  3990.  
  3991.                           if (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
  3992.                               && (S_IS_EXTERNAL (as_sym)
  3993.                                   || S_IS_WEAK (as_sym)
  3994.                                   || ! S_IS_DEFINED (as_sym)))
  3995.                             {
  3996.                               if ((symbol_get_bfdsym (as_sym)->flags
  3997.                                    & BSF_FUNCTION) != 0)
  3998.                                 st = st_Proc;
  3999.                               else
  4000.                                 st = st_Global;
  4001.                             }
  4002.                           else if (seg == text_section)
  4003.                             st = st_Label;
  4004.                           else
  4005.                             st = st_Static;
  4006.  
  4007.                           if (! S_IS_DEFINED (as_sym))
  4008.                             {
  4009.                               valueT s;
  4010.  
  4011.                               s = symbol_get_obj (as_sym)->ecoff_extern_size;
  4012.                               if (s == 0
  4013.                                   || s > bfd_get_gp_size (stdoutput))
  4014.                                 sc = sc_Undefined;
  4015.                               else
  4016.                                 {
  4017.                                   sc = sc_SUndefined;
  4018.                                   sym_ptr->ecoff_sym.asym.value = s;
  4019.                                 }
  4020. #ifdef S_SET_SIZE
  4021.                               S_SET_SIZE (as_sym, s);
  4022. #endif
  4023.                             }
  4024.                           else if (S_IS_COMMON (as_sym))
  4025.                             {
  4026.                               if (S_GET_VALUE (as_sym) > 0
  4027.                                   && (S_GET_VALUE (as_sym)
  4028.                                       <= bfd_get_gp_size (stdoutput)))
  4029.                                 sc = sc_SCommon;
  4030.                               else
  4031.                                 sc = sc_Common;
  4032.                             }
  4033.                           else if (seg == text_section)
  4034.                             sc = sc_Text;
  4035.                           else if (seg == data_section)
  4036.                             sc = sc_Data;
  4037.                           else if (strcmp (segname, ".rdata") == 0
  4038.                                    || strcmp (segname, ".rodata") == 0)
  4039.                             sc = sc_RData;
  4040.                           else if (strcmp (segname, ".sdata") == 0)
  4041.                             sc = sc_SData;
  4042.                           else if (seg == bss_section)
  4043.                             sc = sc_Bss;
  4044.                           else if (strcmp (segname, ".sbss") == 0)
  4045.                             sc = sc_SBss;
  4046.                           else if (seg == bfd_abs_section_ptr)
  4047.                             sc = sc_Abs;
  4048.                           else
  4049.                             {
  4050.                               /* This must be a user named section.
  4051.                                  This is not possible in ECOFF, but it
  4052.                                  is in ELF.  */
  4053.                               sc = sc_Data;
  4054.                             }
  4055.  
  4056.                           sym_ptr->ecoff_sym.asym.st = (int) st;
  4057.                           sym_ptr->ecoff_sym.asym.sc = (int) sc;
  4058.                         }
  4059.  
  4060.                       /* This is just an external symbol if it is
  4061.                          outside a procedure and it has a type.
  4062.                          FIXME: g++ will generate symbols which have
  4063.                          different names in the debugging information
  4064.                          than the actual symbol.  Should we handle
  4065.                          them here?  */
  4066.                       if ((S_IS_EXTERNAL (as_sym)
  4067.                            || S_IS_WEAK (as_sym)
  4068.                            || ! S_IS_DEFINED (as_sym))
  4069.                           && sym_ptr->proc_ptr == (proc_t *) NULL
  4070.                           && sym_ptr->ecoff_sym.asym.st != (int) st_Nil
  4071.                           && ! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym))
  4072.                         local = 0;
  4073.  
  4074.                       /* This is just an external symbol if it is a
  4075.                          common symbol.  */
  4076.                       if (S_IS_COMMON (as_sym))
  4077.                         local = 0;
  4078.  
  4079.                       /* If an st_end symbol has an associated gas
  4080.                          symbol, then it is a local label created for
  4081.                          a .bend or .end directive.  Stabs line
  4082.                          numbers will have \001 in the names.  */
  4083.                       if (local
  4084.                           && sym_ptr->ecoff_sym.asym.st != st_End
  4085.                           && strchr (sym_ptr->name, '\001') == 0)
  4086.                         sym_ptr->ecoff_sym.asym.iss =
  4087.                           add_string (&fil_ptr->strings,
  4088.                                       fil_ptr->str_hash,
  4089.                                       sym_ptr->name,
  4090.                                       (shash_t **) NULL);
  4091.                     }
  4092.  
  4093.                   /* We now know the index of this symbol; fill in
  4094.                      locations that have been waiting for that
  4095.                      information.  */
  4096.                   if (sym_ptr->begin_ptr != (localsym_t *) NULL)
  4097.                     {
  4098.                       localsym_t *begin_ptr;
  4099.                       st_t begin_type;
  4100.  
  4101.                       know (local);
  4102.                       begin_ptr = sym_ptr->begin_ptr;
  4103.                       know (begin_ptr->sym_index != -1);
  4104.                       sym_ptr->ecoff_sym.asym.index = begin_ptr->sym_index;
  4105.                       if (sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
  4106.                         sym_ptr->ecoff_sym.asym.iss =
  4107.                           begin_ptr->ecoff_sym.asym.iss;
  4108.  
  4109.                       begin_type = (st_t) begin_ptr->ecoff_sym.asym.st;
  4110.                       if (begin_type == st_File
  4111.                           || begin_type == st_Block)
  4112.                         {
  4113.                           begin_ptr->ecoff_sym.asym.index =
  4114.                             isym - ifilesym + 1;
  4115.                           (*swap_sym_out) (stdoutput,
  4116.                                            &begin_ptr->ecoff_sym.asym,
  4117.                                            (*buf
  4118.                                             + offset
  4119.                                             + (begin_ptr->sym_index
  4120.                                                * external_sym_size)));
  4121.                         }
  4122.                       else
  4123.                         {
  4124.                           know (begin_ptr->index_ptr != (aux_t *) NULL);
  4125.                           begin_ptr->index_ptr->data.isym =
  4126.                             isym - ifilesym + 1;
  4127.                         }
  4128.  
  4129.                       /* The value of the symbol marking the end of a
  4130.                          procedure is the size of the procedure.  The
  4131.                          value of the symbol marking the end of a
  4132.                          block is the offset from the start of the
  4133.                          procedure to the block.  */
  4134.                       if (begin_type == st_Proc
  4135.                           || begin_type == st_StaticProc)
  4136.                         {
  4137.                           know (as_sym != (symbolS *) NULL);
  4138.                           know (begin_ptr->as_sym != (symbolS *) NULL);
  4139.                           if (S_GET_SEGMENT (as_sym)
  4140.                               != S_GET_SEGMENT (begin_ptr->as_sym))
  4141.                             as_warn (_(".begin/.bend in different segments"));
  4142.                           sym_ptr->ecoff_sym.asym.value =
  4143.                             (S_GET_VALUE (as_sym)
  4144.                              - S_GET_VALUE (begin_ptr->as_sym));
  4145.  
  4146.                           /* If the size is odd, this is probably a
  4147.                              mips16 function; force it to be even.  */
  4148.                           if ((sym_ptr->ecoff_sym.asym.value & 1) != 0)
  4149.                             ++sym_ptr->ecoff_sym.asym.value;
  4150.  
  4151. #ifdef S_SET_SIZE
  4152.                           S_SET_SIZE (begin_ptr->as_sym,
  4153.                                       sym_ptr->ecoff_sym.asym.value);
  4154. #endif
  4155.                         }
  4156.                       else if (begin_type == st_Block
  4157.                                && sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
  4158.                         {
  4159.                           symbolS *begin_sym;
  4160.  
  4161.                           know (as_sym != (symbolS *) NULL);
  4162.                           know (sym_ptr->proc_ptr != (proc_t *) NULL);
  4163.                           begin_sym = sym_ptr->proc_ptr->sym->as_sym;
  4164.                           if (S_GET_SEGMENT (as_sym)
  4165.                               != S_GET_SEGMENT (begin_sym))
  4166.                             as_warn (_(".begin/.bend in different segments"));
  4167.                           sym_ptr->ecoff_sym.asym.value =
  4168.                             S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
  4169.                         }
  4170.                     }
  4171.  
  4172.                   for (f = sym_ptr->forward_ref;
  4173.                        f != (forward_t *) NULL;
  4174.                        f = f->next)
  4175.                     {
  4176.                       know (local);
  4177.                       f->ifd_ptr->data.isym = fil_ptr->file_index;
  4178.                       f->index_ptr->data.rndx.index = isym - ifilesym;
  4179.                     }
  4180.  
  4181.                   if (local)
  4182.                     {
  4183.                       if ((bfd_size_type)(*bufend - sym_out) < external_sym_size)
  4184.                         sym_out = ecoff_add_bytes (buf, bufend,
  4185.                                                    sym_out,
  4186.                                                    external_sym_size);
  4187.                       (*swap_sym_out) (stdoutput, &sym_ptr->ecoff_sym.asym,
  4188.                                        sym_out);
  4189.                       sym_out += external_sym_size;
  4190.  
  4191.                       sym_ptr->sym_index = isym;
  4192.  
  4193.                       if (sym_ptr->proc_ptr != (proc_t *) NULL
  4194.                           && sym_ptr->proc_ptr->sym == sym_ptr)
  4195.                         sym_ptr->proc_ptr->pdr.isym = isym - ifilesym;
  4196.  
  4197.                       ++isym;
  4198.                     }
  4199.  
  4200.                   /* Record the local symbol index and file number in
  4201.                      case this is an external symbol.  Note that this
  4202.                      destroys the asym.index field.  */
  4203.                   if (as_sym != (symbolS *) NULL
  4204.                       && symbol_get_obj (as_sym)->ecoff_symbol == sym_ptr)
  4205.                     {
  4206.                       if ((sym_ptr->ecoff_sym.asym.st == st_Proc
  4207.                            || sym_ptr->ecoff_sym.asym.st == st_StaticProc)
  4208.                           && local)
  4209.                         sym_ptr->ecoff_sym.asym.index = isym - ifilesym - 1;
  4210.                       sym_ptr->ecoff_sym.ifd = fil_ptr->file_index;
  4211.  
  4212.                       /* Don't try to merge an FDR which has an
  4213.                          external symbol attached to it.  */
  4214.                       if (S_IS_EXTERNAL (as_sym) || S_IS_WEAK (as_sym))
  4215.                         fil_ptr->fdr.fMerge = 0;
  4216.                     }
  4217.                 }
  4218.             }
  4219.           fil_ptr->fdr.csym = isym - fil_ptr->fdr.isymBase;
  4220.         }
  4221.     }
  4222.  
  4223.   return offset + isym * external_sym_size;
  4224. }
  4225.  
  4226. /* Swap out the procedure information.  */
  4227.  
  4228. static unsigned long
  4229. ecoff_build_procs (const struct ecoff_debug_swap *backend,
  4230.                    char **buf,
  4231.                    char **bufend,
  4232.                    unsigned long offset)
  4233. {
  4234.   const bfd_size_type external_pdr_size = backend->external_pdr_size;
  4235.   void (* const swap_pdr_out) (bfd *, const PDR *, void *)
  4236.     = backend->swap_pdr_out;
  4237.   char *pdr_out;
  4238.   long iproc;
  4239.   vlinks_t *file_link;
  4240.  
  4241.   pdr_out = *buf + offset;
  4242.  
  4243.   iproc = 0;
  4244.  
  4245.   /* The procedures are stored by file.  */
  4246.   for (file_link = file_desc.first;
  4247.        file_link != (vlinks_t *) NULL;
  4248.        file_link = file_link->next)
  4249.     {
  4250.       int fil_cnt;
  4251.       efdr_t *fil_ptr;
  4252.       efdr_t *fil_end;
  4253.  
  4254.       if (file_link->next == (vlinks_t *) NULL)
  4255.         fil_cnt = file_desc.objects_last_page;
  4256.       else
  4257.         fil_cnt = file_desc.objects_per_page;
  4258.       fil_ptr = file_link->datum->file;
  4259.       fil_end = fil_ptr + fil_cnt;
  4260.       for (; fil_ptr < fil_end; fil_ptr++)
  4261.         {
  4262.           vlinks_t *proc_link;
  4263.           int first;
  4264.  
  4265.           fil_ptr->fdr.ipdFirst = iproc;
  4266.           first = 1;
  4267.           for (proc_link = fil_ptr->procs.first;
  4268.                proc_link != (vlinks_t *) NULL;
  4269.                proc_link = proc_link->next)
  4270.             {
  4271.               int prc_cnt;
  4272.               proc_t *proc_ptr;
  4273.               proc_t *proc_end;
  4274.  
  4275.               if (proc_link->next == (vlinks_t *) NULL)
  4276.                 prc_cnt = fil_ptr->procs.objects_last_page;
  4277.               else
  4278.                 prc_cnt = fil_ptr->procs.objects_per_page;
  4279.               proc_ptr = proc_link->datum->proc;
  4280.               proc_end = proc_ptr + prc_cnt;
  4281.               for (; proc_ptr < proc_end; proc_ptr++)
  4282.                 {
  4283.                   symbolS *adr_sym;
  4284.                   unsigned long adr;
  4285.  
  4286.                   adr_sym = proc_ptr->sym->as_sym;
  4287.                   adr = (S_GET_VALUE (adr_sym)
  4288.                          + bfd_get_section_vma (stdoutput,
  4289.                                                 S_GET_SEGMENT (adr_sym)));
  4290.                   if (first)
  4291.                     {
  4292.                       /* This code used to force the adr of the very
  4293.                          first fdr to be 0.  However, the native tools
  4294.                          don't do that, and I can't remember why it
  4295.                          used to work that way, so I took it out.  */
  4296.                       fil_ptr->fdr.adr = adr;
  4297.                       first = 0;
  4298.                     }
  4299.                   proc_ptr->pdr.adr = adr - fil_ptr->fdr.adr;
  4300.                   if ((bfd_size_type)(*bufend - pdr_out) < external_pdr_size)
  4301.                     pdr_out = ecoff_add_bytes (buf, bufend,
  4302.                                                pdr_out,
  4303.                                                external_pdr_size);
  4304.                   (*swap_pdr_out) (stdoutput, &proc_ptr->pdr, pdr_out);
  4305.                   pdr_out += external_pdr_size;
  4306.                   ++iproc;
  4307.                 }
  4308.             }
  4309.           fil_ptr->fdr.cpd = iproc - fil_ptr->fdr.ipdFirst;
  4310.         }
  4311.     }
  4312.  
  4313.   return offset + iproc * external_pdr_size;
  4314. }
  4315.  
  4316. /* Swap out the aux information.  */
  4317.  
  4318. static unsigned long
  4319. ecoff_build_aux (const struct ecoff_debug_swap *backend,
  4320.                  char **buf,
  4321.                  char **bufend,
  4322.                  unsigned long offset)
  4323. {
  4324.   int bigendian;
  4325.   union aux_ext *aux_out;
  4326.   long iaux;
  4327.   vlinks_t *file_link;
  4328.  
  4329.   bigendian = bfd_big_endian (stdoutput);
  4330.  
  4331.   aux_out = (union aux_ext *) (*buf + offset);
  4332.  
  4333.   iaux = 0;
  4334.  
  4335.   /* The aux entries are stored by file.  */
  4336.   for (file_link = file_desc.first;
  4337.        file_link != (vlinks_t *) NULL;
  4338.        file_link = file_link->next)
  4339.     {
  4340.       int fil_cnt;
  4341.       efdr_t *fil_ptr;
  4342.       efdr_t *fil_end;
  4343.  
  4344.       if (file_link->next == (vlinks_t *) NULL)
  4345.         fil_cnt = file_desc.objects_last_page;
  4346.       else
  4347.         fil_cnt = file_desc.objects_per_page;
  4348.       fil_ptr = file_link->datum->file;
  4349.       fil_end = fil_ptr + fil_cnt;
  4350.       for (; fil_ptr < fil_end; fil_ptr++)
  4351.         {
  4352.           vlinks_t *aux_link;
  4353.  
  4354.           fil_ptr->fdr.fBigendian = bigendian;
  4355.           fil_ptr->fdr.iauxBase = iaux;
  4356.           for (aux_link = fil_ptr->aux_syms.first;
  4357.                aux_link != (vlinks_t *) NULL;
  4358.                aux_link = aux_link->next)
  4359.             {
  4360.               int aux_cnt;
  4361.               aux_t *aux_ptr;
  4362.               aux_t *aux_end;
  4363.  
  4364.               if (aux_link->next == (vlinks_t *) NULL)
  4365.                 aux_cnt = fil_ptr->aux_syms.objects_last_page;
  4366.               else
  4367.                 aux_cnt = fil_ptr->aux_syms.objects_per_page;
  4368.               aux_ptr = aux_link->datum->aux;
  4369.               aux_end = aux_ptr + aux_cnt;
  4370.               for (; aux_ptr < aux_end; aux_ptr++)
  4371.                 {
  4372.                   if ((unsigned long) (*bufend - (char *) aux_out)
  4373.                       < sizeof (union aux_ext))
  4374.                     aux_out = ((union aux_ext *)
  4375.                                ecoff_add_bytes (buf, bufend,
  4376.                                                 (char *) aux_out,
  4377.                                                 sizeof (union aux_ext)));
  4378.                   switch (aux_ptr->type)
  4379.                     {
  4380.                     case aux_tir:
  4381.                       (*backend->swap_tir_out) (bigendian,
  4382.                                                 &aux_ptr->data.ti,
  4383.                                                 &aux_out->a_ti);
  4384.                       break;
  4385.                     case aux_rndx:
  4386.                       (*backend->swap_rndx_out) (bigendian,
  4387.                                                  &aux_ptr->data.rndx,
  4388.                                                  &aux_out->a_rndx);
  4389.                       break;
  4390.                     case aux_dnLow:
  4391.                       AUX_PUT_DNLOW (bigendian, aux_ptr->data.dnLow,
  4392.                                      aux_out);
  4393.                       break;
  4394.                     case aux_dnHigh:
  4395.                       AUX_PUT_DNHIGH (bigendian, aux_ptr->data.dnHigh,
  4396.                                       aux_out);
  4397.                       break;
  4398.                     case aux_isym:
  4399.                       AUX_PUT_ISYM (bigendian, aux_ptr->data.isym,
  4400.                                     aux_out);
  4401.                       break;
  4402.                     case aux_iss:
  4403.                       AUX_PUT_ISS (bigendian, aux_ptr->data.iss,
  4404.                                    aux_out);
  4405.                       break;
  4406.                     case aux_width:
  4407.                       AUX_PUT_WIDTH (bigendian, aux_ptr->data.width,
  4408.                                      aux_out);
  4409.                       break;
  4410.                     case aux_count:
  4411.                       AUX_PUT_COUNT (bigendian, aux_ptr->data.count,
  4412.                                      aux_out);
  4413.                       break;
  4414.                     }
  4415.  
  4416.                   ++aux_out;
  4417.                   ++iaux;
  4418.                 }
  4419.             }
  4420.           fil_ptr->fdr.caux = iaux - fil_ptr->fdr.iauxBase;
  4421.         }
  4422.     }
  4423.  
  4424.   return ecoff_padding_adjust (backend, buf, bufend,
  4425.                                offset + iaux * sizeof (union aux_ext),
  4426.                                (char **) NULL);
  4427. }
  4428.  
  4429. /* Copy out the strings from a varray_t.  This returns the number of
  4430.    bytes copied, rather than the new offset.  */
  4431.  
  4432. static unsigned long
  4433. ecoff_build_strings (char **buf,
  4434.                      char **bufend,
  4435.                      unsigned long offset,
  4436.                      varray_t *vp)
  4437. {
  4438.   unsigned long istr;
  4439.   char *str_out;
  4440.   vlinks_t *str_link;
  4441.  
  4442.   str_out = *buf + offset;
  4443.  
  4444.   istr = 0;
  4445.  
  4446.   for (str_link = vp->first;
  4447.        str_link != (vlinks_t *) NULL;
  4448.        str_link = str_link->next)
  4449.     {
  4450.       unsigned long str_cnt;
  4451.  
  4452.       if (str_link->next == (vlinks_t *) NULL)
  4453.         str_cnt = vp->objects_last_page;
  4454.       else
  4455.         str_cnt = vp->objects_per_page;
  4456.  
  4457.       if ((unsigned long)(*bufend - str_out) < str_cnt)
  4458.         str_out = ecoff_add_bytes (buf, bufend, str_out, str_cnt);
  4459.  
  4460.       memcpy (str_out, str_link->datum->byte, str_cnt);
  4461.       str_out += str_cnt;
  4462.       istr += str_cnt;
  4463.     }
  4464.  
  4465.   return istr;
  4466. }
  4467.  
  4468. /* Dump out the local strings.  */
  4469.  
  4470. static unsigned long
  4471. ecoff_build_ss (const struct ecoff_debug_swap *backend,
  4472.                 char **buf,
  4473.                 char **bufend,
  4474.                 unsigned long offset)
  4475. {
  4476.   long iss;
  4477.   vlinks_t *file_link;
  4478.  
  4479.   iss = 0;
  4480.  
  4481.   for (file_link = file_desc.first;
  4482.        file_link != (vlinks_t *) NULL;
  4483.        file_link = file_link->next)
  4484.     {
  4485.       int fil_cnt;
  4486.       efdr_t *fil_ptr;
  4487.       efdr_t *fil_end;
  4488.  
  4489.       if (file_link->next == (vlinks_t *) NULL)
  4490.         fil_cnt = file_desc.objects_last_page;
  4491.       else
  4492.         fil_cnt = file_desc.objects_per_page;
  4493.       fil_ptr = file_link->datum->file;
  4494.       fil_end = fil_ptr + fil_cnt;
  4495.       for (; fil_ptr < fil_end; fil_ptr++)
  4496.         {
  4497.           long ss_cnt;
  4498.  
  4499.           fil_ptr->fdr.issBase = iss;
  4500.           ss_cnt = ecoff_build_strings (buf, bufend, offset + iss,
  4501.                                         &fil_ptr->strings);
  4502.           fil_ptr->fdr.cbSs = ss_cnt;
  4503.           iss += ss_cnt;
  4504.         }
  4505.     }
  4506.  
  4507.   return ecoff_padding_adjust (backend, buf, bufend, offset + iss,
  4508.                                (char **) NULL);
  4509. }
  4510.  
  4511. /* Swap out the file descriptors.  */
  4512.  
  4513. static unsigned long
  4514. ecoff_build_fdr (const struct ecoff_debug_swap *backend,
  4515.                  char **buf,
  4516.                  char **bufend,
  4517.                  unsigned long offset)
  4518. {
  4519.   const bfd_size_type external_fdr_size = backend->external_fdr_size;
  4520.   void (* const swap_fdr_out) (bfd *, const FDR *, void *)
  4521.     = backend->swap_fdr_out;
  4522.   long ifile;
  4523.   char *fdr_out;
  4524.   vlinks_t *file_link;
  4525.  
  4526.   ifile = 0;
  4527.  
  4528.   fdr_out = *buf + offset;
  4529.  
  4530.   for (file_link = file_desc.first;
  4531.        file_link != (vlinks_t *) NULL;
  4532.        file_link = file_link->next)
  4533.     {
  4534.       int fil_cnt;
  4535.       efdr_t *fil_ptr;
  4536.       efdr_t *fil_end;
  4537.  
  4538.       if (file_link->next == (vlinks_t *) NULL)
  4539.         fil_cnt = file_desc.objects_last_page;
  4540.       else
  4541.         fil_cnt = file_desc.objects_per_page;
  4542.       fil_ptr = file_link->datum->file;
  4543.       fil_end = fil_ptr + fil_cnt;
  4544.       for (; fil_ptr < fil_end; fil_ptr++)
  4545.         {
  4546.           if ((bfd_size_type)(*bufend - fdr_out) < external_fdr_size)
  4547.             fdr_out = ecoff_add_bytes (buf, bufend, fdr_out,
  4548.                                        external_fdr_size);
  4549.           (*swap_fdr_out) (stdoutput, &fil_ptr->fdr, fdr_out);
  4550.           fdr_out += external_fdr_size;
  4551.           ++ifile;
  4552.         }
  4553.     }
  4554.  
  4555.   return offset + ifile * external_fdr_size;
  4556. }
  4557.  
  4558. /* Set up the external symbols.  These are supposed to be handled by
  4559.    the backend.  This routine just gets the right information and
  4560.    calls a backend function to deal with it.  */
  4561.  
  4562. static void
  4563. ecoff_setup_ext (void)
  4564. {
  4565.   register symbolS *sym;
  4566.  
  4567.   for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
  4568.     {
  4569.       if (symbol_get_obj (sym)->ecoff_symbol == NULL)
  4570.         continue;
  4571.  
  4572.       /* If this is a local symbol, then force the fields to zero.  */
  4573.       if (! S_IS_EXTERNAL (sym)
  4574.           && ! S_IS_WEAK (sym)
  4575.           && S_IS_DEFINED (sym))
  4576.         {
  4577.           struct localsym *lsym;
  4578.  
  4579.           lsym = symbol_get_obj (sym)->ecoff_symbol;
  4580.           lsym->ecoff_sym.asym.value = 0;
  4581.           lsym->ecoff_sym.asym.st = (int) st_Nil;
  4582.           lsym->ecoff_sym.asym.sc = (int) sc_Nil;
  4583.           lsym->ecoff_sym.asym.index = indexNil;
  4584.         }
  4585.  
  4586.       obj_ecoff_set_ext (sym, &symbol_get_obj (sym)->ecoff_symbol->ecoff_sym);
  4587.     }
  4588. }
  4589.  
  4590. /* Build the ECOFF debugging information.  */
  4591.  
  4592. unsigned long
  4593. ecoff_build_debug (HDRR *hdr,
  4594.                    char **bufp,
  4595.                    const struct ecoff_debug_swap *backend)
  4596. {
  4597.   const bfd_size_type external_pdr_size = backend->external_pdr_size;
  4598.   tag_t *ptag;
  4599.   tag_t *ptag_next;
  4600.   efdr_t *fil_ptr;
  4601.   int end_warning;
  4602.   efdr_t *hold_file_ptr;
  4603.   proc_t *hold_proc_ptr;
  4604.   symbolS *sym;
  4605.   char *buf;
  4606.   char *bufend;
  4607.   unsigned long offset;
  4608.  
  4609.   /* Make sure we have a file.  */
  4610.   if (first_file == (efdr_t *) NULL)
  4611.     add_file ((const char *) NULL, 0, 1);
  4612.  
  4613.   /* Handle any top level tags.  */
  4614.   for (ptag = top_tag_head->first_tag;
  4615.        ptag != (tag_t *) NULL;
  4616.        ptag = ptag_next)
  4617.     {
  4618.       if (ptag->forward_ref != (forward_t *) NULL)
  4619.         add_unknown_tag (ptag);
  4620.  
  4621.       ptag_next = ptag->same_block;
  4622.       ptag->hash_ptr->tag_ptr = ptag->same_name;
  4623.       free_tag (ptag);
  4624.     }
  4625.  
  4626.   free_thead (top_tag_head);
  4627.  
  4628.   /* Look through the symbols.  Add debugging information for each
  4629.      symbol that has not already received it.  */
  4630.   hold_file_ptr = cur_file_ptr;
  4631.   hold_proc_ptr = cur_proc_ptr;
  4632.   cur_proc_ptr = (proc_t *) NULL;
  4633.   for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
  4634.     {
  4635.       if (symbol_get_obj (sym)->ecoff_symbol != NULL
  4636.           || symbol_get_obj (sym)->ecoff_file == (efdr_t *) NULL
  4637.           || (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0)
  4638.         continue;
  4639.  
  4640.       cur_file_ptr = symbol_get_obj (sym)->ecoff_file;
  4641.       add_ecoff_symbol ((const char *) NULL, st_Nil, sc_Nil, sym,
  4642.                         (bfd_vma) 0, S_GET_VALUE (sym), indexNil);
  4643.     }
  4644.   cur_proc_ptr = hold_proc_ptr;
  4645.   cur_file_ptr = hold_file_ptr;
  4646.  
  4647.   /* Output an ending symbol for all the files.  We have to do this
  4648.      here for the last file, so we may as well do it for all of the
  4649.      files.  */
  4650.   end_warning = 0;
  4651.   for (fil_ptr = first_file;
  4652.        fil_ptr != (efdr_t *) NULL;
  4653.        fil_ptr = fil_ptr->next_file)
  4654.     {
  4655.       cur_file_ptr = fil_ptr;
  4656.       while (cur_file_ptr->cur_scope != (scope_t *) NULL
  4657.              && cur_file_ptr->cur_scope->prev != (scope_t *) NULL)
  4658.         {
  4659.           cur_file_ptr->cur_scope = cur_file_ptr->cur_scope->prev;
  4660.           if (! end_warning && ! cur_file_ptr->fake)
  4661.             {
  4662.               as_warn (_("missing .end or .bend at end of file"));
  4663.               end_warning = 1;
  4664.             }
  4665.         }
  4666.       if (cur_file_ptr->cur_scope != (scope_t *) NULL)
  4667.         (void) add_ecoff_symbol ((const char *) NULL,
  4668.                                  st_End, sc_Text,
  4669.                                  (symbolS *) NULL,
  4670.                                  (bfd_vma) 0,
  4671.                                  (symint_t) 0,
  4672.                                  (symint_t) 0);
  4673.     }
  4674.  
  4675.   /* Build the symbolic information.  */
  4676.   offset = 0;
  4677.   buf = (char *) xmalloc (PAGE_SIZE);
  4678.   bufend = buf + PAGE_SIZE;
  4679.  
  4680.   /* Build the line number information.  */
  4681.   hdr->cbLineOffset = offset;
  4682.   offset = ecoff_build_lineno (backend, &buf, &bufend, offset,
  4683.                                &hdr->ilineMax);
  4684.   hdr->cbLine = offset - hdr->cbLineOffset;
  4685.  
  4686.   /* We don't use dense numbers at all.  */
  4687.   hdr->idnMax = 0;
  4688.   hdr->cbDnOffset = 0;
  4689.  
  4690.   /* We can't build the PDR table until we have built the symbols,
  4691.      because a PDR contains a symbol index.  However, we set aside
  4692.      space at this point.  */
  4693.   hdr->ipdMax = proc_cnt;
  4694.   hdr->cbPdOffset = offset;
  4695.   if ((bfd_size_type)(bufend - (buf + offset)) < proc_cnt * external_pdr_size)
  4696.     (void) ecoff_add_bytes (&buf, &bufend, buf + offset,
  4697.                             proc_cnt * external_pdr_size);
  4698.   offset += proc_cnt * external_pdr_size;
  4699.  
  4700.   /* Build the local symbols.  */
  4701.   hdr->cbSymOffset = offset;
  4702.   offset = ecoff_build_symbols (backend, &buf, &bufend, offset);
  4703.   hdr->isymMax = (offset - hdr->cbSymOffset) / backend->external_sym_size;
  4704.  
  4705.   /* Building the symbols initializes the symbol index in the PDR's.
  4706.      Now we can swap out the PDR's.  */
  4707.   (void) ecoff_build_procs (backend, &buf, &bufend, hdr->cbPdOffset);
  4708.  
  4709.   /* We don't use optimization symbols.  */
  4710.   hdr->ioptMax = 0;
  4711.   hdr->cbOptOffset = 0;
  4712.  
  4713.   /* Swap out the auxiliary type information.  */
  4714.   hdr->cbAuxOffset = offset;
  4715.   offset = ecoff_build_aux (backend, &buf, &bufend, offset);
  4716.   hdr->iauxMax = (offset - hdr->cbAuxOffset) / sizeof (union aux_ext);
  4717.  
  4718.   /* Copy out the local strings.  */
  4719.   hdr->cbSsOffset = offset;
  4720.   offset = ecoff_build_ss (backend, &buf, &bufend, offset);
  4721.   hdr->issMax = offset - hdr->cbSsOffset;
  4722.  
  4723.   /* We don't use relative file descriptors.  */
  4724.   hdr->crfd = 0;
  4725.   hdr->cbRfdOffset = 0;
  4726.  
  4727.   /* Swap out the file descriptors.  */
  4728.   hdr->cbFdOffset = offset;
  4729.   offset = ecoff_build_fdr (backend, &buf, &bufend, offset);
  4730.   hdr->ifdMax = (offset - hdr->cbFdOffset) / backend->external_fdr_size;
  4731.  
  4732.   /* Set up the external symbols, which are handled by the BFD back
  4733.      end.  */
  4734.   hdr->issExtMax = 0;
  4735.   hdr->cbSsExtOffset = 0;
  4736.   hdr->iextMax = 0;
  4737.   hdr->cbExtOffset = 0;
  4738.   ecoff_setup_ext ();
  4739.  
  4740.   know ((offset & (backend->debug_align - 1)) == 0);
  4741.  
  4742.   /* FIXME: This value should be determined from the .verstamp directive,
  4743.      with reasonable defaults in config files.  */
  4744. #ifdef TC_ALPHA
  4745.   hdr->vstamp = 0x030b;
  4746. #else
  4747.   hdr->vstamp = 0x020b;
  4748. #endif
  4749.  
  4750.   *bufp = buf;
  4751.   return offset;
  4752. }
  4753. /* Allocate a cluster of pages.  */
  4754.  
  4755. #ifndef MALLOC_CHECK
  4756.  
  4757. static page_type *
  4758. allocate_cluster (unsigned long npages)
  4759. {
  4760.   register page_type *value = (page_type *) xmalloc (npages * PAGE_USIZE);
  4761.  
  4762. #ifdef ECOFF_DEBUG
  4763.   if (debug > 3)
  4764.     fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value);
  4765. #endif
  4766.  
  4767.   memset (value, 0, npages * PAGE_USIZE);
  4768.  
  4769.   return value;
  4770. }
  4771.  
  4772. static page_type *cluster_ptr = NULL;
  4773. static unsigned long pages_left = 0;
  4774.  
  4775. #endif /* MALLOC_CHECK */
  4776.  
  4777. /* Allocate one page (which is initialized to 0).  */
  4778.  
  4779. static page_type *
  4780. allocate_page (void)
  4781. {
  4782. #ifndef MALLOC_CHECK
  4783.  
  4784.   if (pages_left == 0)
  4785.     {
  4786.       pages_left = MAX_CLUSTER_PAGES;
  4787.       cluster_ptr = allocate_cluster (pages_left);
  4788.     }
  4789.  
  4790.   pages_left--;
  4791.   return cluster_ptr++;
  4792.  
  4793. #else /* MALLOC_CHECK */
  4794.  
  4795.   page_type *ptr;
  4796.  
  4797.   ptr = xmalloc (PAGE_USIZE);
  4798.   memset (ptr, 0, PAGE_USIZE);
  4799.   return ptr;
  4800.  
  4801. #endif /* MALLOC_CHECK */
  4802. }
  4803. /* Allocate scoping information.  */
  4804.  
  4805. static scope_t *
  4806. allocate_scope (void)
  4807. {
  4808.   register scope_t *ptr;
  4809.   static scope_t initial_scope;
  4810.  
  4811. #ifndef MALLOC_CHECK
  4812.  
  4813.   ptr = alloc_counts[(int) alloc_type_scope].free_list.f_scope;
  4814.   if (ptr != (scope_t *) NULL)
  4815.     alloc_counts[(int) alloc_type_scope].free_list.f_scope = ptr->free;
  4816.   else
  4817.     {
  4818.       register int unallocated  = alloc_counts[(int) alloc_type_scope].unallocated;
  4819.       register page_type *cur_page      = alloc_counts[(int) alloc_type_scope].cur_page;
  4820.  
  4821.       if (unallocated == 0)
  4822.         {
  4823.           unallocated = PAGE_SIZE / sizeof (scope_t);
  4824.           alloc_counts[(int) alloc_type_scope].cur_page = cur_page = allocate_page ();
  4825.           alloc_counts[(int) alloc_type_scope].total_pages++;
  4826.         }
  4827.  
  4828.       ptr = &cur_page->scope[--unallocated];
  4829.       alloc_counts[(int) alloc_type_scope].unallocated = unallocated;
  4830.     }
  4831.  
  4832. #else
  4833.  
  4834.   ptr = (scope_t *) xmalloc (sizeof (scope_t));
  4835.  
  4836. #endif
  4837.  
  4838.   alloc_counts[(int) alloc_type_scope].total_alloc++;
  4839.   *ptr = initial_scope;
  4840.   return ptr;
  4841. }
  4842.  
  4843. /* Free scoping information.  */
  4844.  
  4845. static void
  4846. free_scope (scope_t *ptr)
  4847. {
  4848.   alloc_counts[(int) alloc_type_scope].total_free++;
  4849.  
  4850. #ifndef MALLOC_CHECK
  4851.   ptr->free = alloc_counts[(int) alloc_type_scope].free_list.f_scope;
  4852.   alloc_counts[(int) alloc_type_scope].free_list.f_scope = ptr;
  4853. #else
  4854.   free ((void *) ptr);
  4855. #endif
  4856. }
  4857. /* Allocate links for pages in a virtual array.  */
  4858.  
  4859. static vlinks_t *
  4860. allocate_vlinks (void)
  4861. {
  4862.   register vlinks_t *ptr;
  4863.   static vlinks_t initial_vlinks;
  4864.  
  4865. #ifndef MALLOC_CHECK
  4866.  
  4867.   register int unallocated = alloc_counts[(int) alloc_type_vlinks].unallocated;
  4868.   register page_type *cur_page = alloc_counts[(int) alloc_type_vlinks].cur_page;
  4869.  
  4870.   if (unallocated == 0)
  4871.     {
  4872.       unallocated = PAGE_SIZE / sizeof (vlinks_t);
  4873.       alloc_counts[(int) alloc_type_vlinks].cur_page = cur_page = allocate_page ();
  4874.       alloc_counts[(int) alloc_type_vlinks].total_pages++;
  4875.     }
  4876.  
  4877.   ptr = &cur_page->vlinks[--unallocated];
  4878.   alloc_counts[(int) alloc_type_vlinks].unallocated = unallocated;
  4879.  
  4880. #else
  4881.  
  4882.   ptr = (vlinks_t *) xmalloc (sizeof (vlinks_t));
  4883.  
  4884. #endif
  4885.  
  4886.   alloc_counts[(int) alloc_type_vlinks].total_alloc++;
  4887.   *ptr = initial_vlinks;
  4888.   return ptr;
  4889. }
  4890. /* Allocate string hash buckets.  */
  4891.  
  4892. static shash_t *
  4893. allocate_shash (void)
  4894. {
  4895.   register shash_t *ptr;
  4896.   static shash_t initial_shash;
  4897.  
  4898. #ifndef MALLOC_CHECK
  4899.  
  4900.   register int unallocated = alloc_counts[(int) alloc_type_shash].unallocated;
  4901.   register page_type *cur_page = alloc_counts[(int) alloc_type_shash].cur_page;
  4902.  
  4903.   if (unallocated == 0)
  4904.     {
  4905.       unallocated = PAGE_SIZE / sizeof (shash_t);
  4906.       alloc_counts[(int) alloc_type_shash].cur_page = cur_page = allocate_page ();
  4907.       alloc_counts[(int) alloc_type_shash].total_pages++;
  4908.     }
  4909.  
  4910.   ptr = &cur_page->shash[--unallocated];
  4911.   alloc_counts[(int) alloc_type_shash].unallocated = unallocated;
  4912.  
  4913. #else
  4914.  
  4915.   ptr = (shash_t *) xmalloc (sizeof (shash_t));
  4916.  
  4917. #endif
  4918.  
  4919.   alloc_counts[(int) alloc_type_shash].total_alloc++;
  4920.   *ptr = initial_shash;
  4921.   return ptr;
  4922. }
  4923. /* Allocate type hash buckets.  */
  4924.  
  4925. static thash_t *
  4926. allocate_thash (void)
  4927. {
  4928.   register thash_t *ptr;
  4929.   static thash_t initial_thash;
  4930.  
  4931. #ifndef MALLOC_CHECK
  4932.  
  4933.   register int unallocated = alloc_counts[(int) alloc_type_thash].unallocated;
  4934.   register page_type *cur_page = alloc_counts[(int) alloc_type_thash].cur_page;
  4935.  
  4936.   if (unallocated == 0)
  4937.     {
  4938.       unallocated = PAGE_SIZE / sizeof (thash_t);
  4939.       alloc_counts[(int) alloc_type_thash].cur_page = cur_page = allocate_page ();
  4940.       alloc_counts[(int) alloc_type_thash].total_pages++;
  4941.     }
  4942.  
  4943.   ptr = &cur_page->thash[--unallocated];
  4944.   alloc_counts[(int) alloc_type_thash].unallocated = unallocated;
  4945.  
  4946. #else
  4947.  
  4948.   ptr = (thash_t *) xmalloc (sizeof (thash_t));
  4949.  
  4950. #endif
  4951.  
  4952.   alloc_counts[(int) alloc_type_thash].total_alloc++;
  4953.   *ptr = initial_thash;
  4954.   return ptr;
  4955. }
  4956. /* Allocate structure, union, or enum tag information.  */
  4957.  
  4958. static tag_t *
  4959. allocate_tag (void)
  4960. {
  4961.   register tag_t *ptr;
  4962.   static tag_t initial_tag;
  4963.  
  4964. #ifndef MALLOC_CHECK
  4965.  
  4966.   ptr = alloc_counts[(int) alloc_type_tag].free_list.f_tag;
  4967.   if (ptr != (tag_t *) NULL)
  4968.     alloc_counts[(int) alloc_type_tag].free_list.f_tag = ptr->free;
  4969.   else
  4970.     {
  4971.       register int unallocated = alloc_counts[(int) alloc_type_tag].unallocated;
  4972.       register page_type *cur_page = alloc_counts[(int) alloc_type_tag].cur_page;
  4973.  
  4974.       if (unallocated == 0)
  4975.         {
  4976.           unallocated = PAGE_SIZE / sizeof (tag_t);
  4977.           alloc_counts[(int) alloc_type_tag].cur_page = cur_page = allocate_page ();
  4978.           alloc_counts[(int) alloc_type_tag].total_pages++;
  4979.         }
  4980.  
  4981.       ptr = &cur_page->tag[--unallocated];
  4982.       alloc_counts[(int) alloc_type_tag].unallocated = unallocated;
  4983.     }
  4984.  
  4985. #else
  4986.  
  4987.   ptr = (tag_t *) xmalloc (sizeof (tag_t));
  4988.  
  4989. #endif
  4990.  
  4991.   alloc_counts[(int) alloc_type_tag].total_alloc++;
  4992.   *ptr = initial_tag;
  4993.   return ptr;
  4994. }
  4995.  
  4996. /* Free scoping information.  */
  4997.  
  4998. static void
  4999. free_tag (tag_t *ptr)
  5000. {
  5001.   alloc_counts[(int) alloc_type_tag].total_free++;
  5002.  
  5003. #ifndef MALLOC_CHECK
  5004.   ptr->free = alloc_counts[(int) alloc_type_tag].free_list.f_tag;
  5005.   alloc_counts[(int) alloc_type_tag].free_list.f_tag = ptr;
  5006. #else
  5007.   free ((PTR_T) ptr);
  5008. #endif
  5009. }
  5010. /* Allocate forward reference to a yet unknown tag.  */
  5011.  
  5012. static forward_t *
  5013. allocate_forward (void)
  5014. {
  5015.   register forward_t *ptr;
  5016.   static forward_t initial_forward;
  5017.  
  5018. #ifndef MALLOC_CHECK
  5019.  
  5020.   register int unallocated = alloc_counts[(int) alloc_type_forward].unallocated;
  5021.   register page_type *cur_page = alloc_counts[(int) alloc_type_forward].cur_page;
  5022.  
  5023.   if (unallocated == 0)
  5024.     {
  5025.       unallocated = PAGE_SIZE / sizeof (forward_t);
  5026.       alloc_counts[(int) alloc_type_forward].cur_page = cur_page = allocate_page ();
  5027.       alloc_counts[(int) alloc_type_forward].total_pages++;
  5028.     }
  5029.  
  5030.   ptr = &cur_page->forward[--unallocated];
  5031.   alloc_counts[(int) alloc_type_forward].unallocated = unallocated;
  5032.  
  5033. #else
  5034.  
  5035.   ptr = (forward_t *) xmalloc (sizeof (forward_t));
  5036.  
  5037. #endif
  5038.  
  5039.   alloc_counts[(int) alloc_type_forward].total_alloc++;
  5040.   *ptr = initial_forward;
  5041.   return ptr;
  5042. }
  5043. /* Allocate head of type hash list.  */
  5044.  
  5045. static thead_t *
  5046. allocate_thead (void)
  5047. {
  5048.   register thead_t *ptr;
  5049.   static thead_t initial_thead;
  5050.  
  5051. #ifndef MALLOC_CHECK
  5052.  
  5053.   ptr = alloc_counts[(int) alloc_type_thead].free_list.f_thead;
  5054.   if (ptr != (thead_t *) NULL)
  5055.     alloc_counts[(int) alloc_type_thead].free_list.f_thead = ptr->free;
  5056.   else
  5057.     {
  5058.       register int unallocated = alloc_counts[(int) alloc_type_thead].unallocated;
  5059.       register page_type *cur_page = alloc_counts[(int) alloc_type_thead].cur_page;
  5060.  
  5061.       if (unallocated == 0)
  5062.         {
  5063.           unallocated = PAGE_SIZE / sizeof (thead_t);
  5064.           alloc_counts[(int) alloc_type_thead].cur_page = cur_page = allocate_page ();
  5065.           alloc_counts[(int) alloc_type_thead].total_pages++;
  5066.         }
  5067.  
  5068.       ptr = &cur_page->thead[--unallocated];
  5069.       alloc_counts[(int) alloc_type_thead].unallocated = unallocated;
  5070.     }
  5071.  
  5072. #else
  5073.  
  5074.   ptr = (thead_t *) xmalloc (sizeof (thead_t));
  5075.  
  5076. #endif
  5077.  
  5078.   alloc_counts[(int) alloc_type_thead].total_alloc++;
  5079.   *ptr = initial_thead;
  5080.   return ptr;
  5081. }
  5082.  
  5083. /* Free scoping information.  */
  5084.  
  5085. static void
  5086. free_thead (thead_t *ptr)
  5087. {
  5088.   alloc_counts[(int) alloc_type_thead].total_free++;
  5089.  
  5090. #ifndef MALLOC_CHECK
  5091.   ptr->free = (thead_t *) alloc_counts[(int) alloc_type_thead].free_list.f_thead;
  5092.   alloc_counts[(int) alloc_type_thead].free_list.f_thead = ptr;
  5093. #else
  5094.   free ((PTR_T) ptr);
  5095. #endif
  5096. }
  5097. static lineno_list_t *
  5098. allocate_lineno_list (void)
  5099. {
  5100.   register lineno_list_t *ptr;
  5101.   static lineno_list_t initial_lineno_list;
  5102.  
  5103. #ifndef MALLOC_CHECK
  5104.  
  5105.   register int unallocated = alloc_counts[(int) alloc_type_lineno].unallocated;
  5106.   register page_type *cur_page = alloc_counts[(int) alloc_type_lineno].cur_page;
  5107.  
  5108.   if (unallocated == 0)
  5109.     {
  5110.       unallocated = PAGE_SIZE / sizeof (lineno_list_t);
  5111.       alloc_counts[(int) alloc_type_lineno].cur_page = cur_page = allocate_page ();
  5112.       alloc_counts[(int) alloc_type_lineno].total_pages++;
  5113.     }
  5114.  
  5115.   ptr = &cur_page->lineno[--unallocated];
  5116.   alloc_counts[(int) alloc_type_lineno].unallocated = unallocated;
  5117.  
  5118. #else
  5119.  
  5120.   ptr = (lineno_list_t *) xmalloc (sizeof (lineno_list_t));
  5121.  
  5122. #endif
  5123.  
  5124.   alloc_counts[(int) alloc_type_lineno].total_alloc++;
  5125.   *ptr = initial_lineno_list;
  5126.   return ptr;
  5127. }
  5128.  
  5129. void
  5130. ecoff_set_gp_prolog_size (int sz)
  5131. {
  5132.   if (cur_proc_ptr == 0)
  5133.     return;
  5134.  
  5135.   cur_proc_ptr->pdr.gp_prologue = sz;
  5136.   if (cur_proc_ptr->pdr.gp_prologue != sz)
  5137.     {
  5138.       as_warn (_("GP prologue size exceeds field size, using 0 instead"));
  5139.       cur_proc_ptr->pdr.gp_prologue = 0;
  5140.     }
  5141.  
  5142.   cur_proc_ptr->pdr.gp_used = 1;
  5143. }
  5144.  
  5145. int
  5146. ecoff_no_current_file (void)
  5147. {
  5148.   return cur_file_ptr == (efdr_t *) NULL;
  5149. }
  5150.  
  5151. void
  5152. ecoff_generate_asm_lineno (void)
  5153. {
  5154.   unsigned int lineno;
  5155.   char *filename;
  5156.   lineno_list_t *list;
  5157.  
  5158.   as_where (&filename, &lineno);
  5159.  
  5160.   if (current_stabs_filename == (char *) NULL
  5161.       || filename_cmp (current_stabs_filename, filename))
  5162.     add_file (filename, 0, 1);
  5163.  
  5164.   list = allocate_lineno_list ();
  5165.  
  5166.   list->next = (lineno_list_t *) NULL;
  5167.   list->file = cur_file_ptr;
  5168.   list->proc = cur_proc_ptr;
  5169.   list->frag = frag_now;
  5170.   list->paddr = frag_now_fix ();
  5171.   list->lineno = lineno;
  5172.  
  5173.   /* We don't want to merge files which have line numbers.  */
  5174.   cur_file_ptr->fdr.fMerge = 0;
  5175.  
  5176.   /* A .loc directive will sometimes appear before a .ent directive,
  5177.      which means that cur_proc_ptr will be NULL here.  Arrange to
  5178.      patch this up.  */
  5179.   if (cur_proc_ptr == (proc_t *) NULL)
  5180.     {
  5181.       lineno_list_t **pl;
  5182.  
  5183.       pl = &noproc_lineno;
  5184.       while (*pl != (lineno_list_t *) NULL)
  5185.         pl = &(*pl)->next;
  5186.       *pl = list;
  5187.     }
  5188.   else
  5189.     {
  5190.       last_lineno = list;
  5191.       *last_lineno_ptr = list;
  5192.       last_lineno_ptr = &list->next;
  5193.     }
  5194. }
  5195.  
  5196. #else
  5197.  
  5198. void
  5199. ecoff_generate_asm_lineno (void)
  5200. {
  5201. }
  5202.  
  5203. #endif /* ECOFF_DEBUGGING */
  5204.