Coverage Report

Created: 2026-03-10 08:46

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