Coverage Report

Created: 2026-07-25 10:20

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
  if (name == NULL)
3090
    {
3091
      ignore_rest_of_line ();
3092
      return;
3093
    }
3094
3095
  add_file (name, indx - 1, 0);
3096
3097
  demand_empty_rest_of_line ();
3098
}
3099

3100
/* Parse .fmask directives.  */
3101
3102
void
3103
ecoff_directive_fmask (int ignore ATTRIBUTE_UNUSED)
3104
{
3105
  long val;
3106
3107
  if (cur_proc_ptr == NULL)
3108
    {
3109
      as_warn (_(".fmask outside of .ent"));
3110
      demand_empty_rest_of_line ();
3111
      return;
3112
    }
3113
3114
  if (get_absolute_expression_and_terminator (&val) != ',')
3115
    {
3116
      as_warn (_("bad .fmask directive"));
3117
      --input_line_pointer;
3118
      demand_empty_rest_of_line ();
3119
      return;
3120
    }
3121
3122
  cur_proc_ptr->pdr.fregmask = val;
3123
  cur_proc_ptr->pdr.fregoffset = get_absolute_expression ();
3124
3125
  demand_empty_rest_of_line ();
3126
}
3127

3128
/* Parse .frame directives.  */
3129
3130
void
3131
ecoff_directive_frame (int ignore ATTRIBUTE_UNUSED)
3132
{
3133
  long val;
3134
3135
  if (cur_proc_ptr == NULL)
3136
    {
3137
      as_warn (_(".frame outside of .ent"));
3138
      demand_empty_rest_of_line ();
3139
      return;
3140
    }
3141
3142
  cur_proc_ptr->pdr.framereg = tc_get_register (1);
3143
3144
  SKIP_WHITESPACE ();
3145
  if (*input_line_pointer++ != ','
3146
      || get_absolute_expression_and_terminator (&val) != ',')
3147
    {
3148
      as_warn (_("bad .frame directive"));
3149
      --input_line_pointer;
3150
      demand_empty_rest_of_line ();
3151
      return;
3152
    }
3153
3154
  cur_proc_ptr->pdr.frameoffset = val;
3155
3156
  cur_proc_ptr->pdr.pcreg = tc_get_register (0);
3157
3158
  /* Alpha-OSF1 adds "the offset of saved $a0 from $sp", according to
3159
     Sandro.  I don't yet know where this value should be stored, if
3160
     anywhere.  Don't call demand_empty_rest_of_line ().  */
3161
  s_ignore (42);
3162
}
3163

3164
/* Parse .mask directives.  */
3165
3166
void
3167
ecoff_directive_mask (int ignore ATTRIBUTE_UNUSED)
3168
{
3169
  long val;
3170
3171
  if (cur_proc_ptr == NULL)
3172
    {
3173
      as_warn (_(".mask outside of .ent"));
3174
      demand_empty_rest_of_line ();
3175
      return;
3176
    }
3177
3178
  if (get_absolute_expression_and_terminator (&val) != ',')
3179
    {
3180
      as_warn (_("bad .mask directive"));
3181
      --input_line_pointer;
3182
      demand_empty_rest_of_line ();
3183
      return;
3184
    }
3185
3186
  cur_proc_ptr->pdr.regmask = val;
3187
  cur_proc_ptr->pdr.regoffset = get_absolute_expression ();
3188
3189
  demand_empty_rest_of_line ();
3190
}
3191

3192
/* Parse .loc directives.  */
3193
3194
void
3195
ecoff_directive_loc (int ignore ATTRIBUTE_UNUSED)
3196
{
3197
  lineno_list_t *list;
3198
  symint_t lineno;
3199
3200
  if (cur_file_ptr == NULL)
3201
    {
3202
      as_warn (_(".loc before .file"));
3203
      demand_empty_rest_of_line ();
3204
      return;
3205
    }
3206
3207
  if (now_seg != text_section)
3208
    {
3209
      as_warn (_(".loc outside of .text"));
3210
      demand_empty_rest_of_line ();
3211
      return;
3212
    }
3213
3214
  /* Skip the file number.  */
3215
  SKIP_WHITESPACE ();
3216
  get_absolute_expression ();
3217
  SKIP_WHITESPACE ();
3218
3219
  lineno = get_absolute_expression ();
3220
3221
#ifndef NO_LISTING
3222
  if (listing)
3223
    listing_source_line (lineno);
3224
#endif
3225
3226
  /* If we're building stabs, then output a special label rather than
3227
     ECOFF line number info.  */
3228
  if (stabs_seen)
3229
    {
3230
      (void) add_ecoff_symbol (NULL, st_Label, sc_Text,
3231
             symbol_new (FAKE_LABEL_NAME, now_seg,
3232
             frag_now, frag_now_fix ()),
3233
             0, 0, lineno);
3234
      return;
3235
    }
3236
3237
  list = allocate_lineno_list ();
3238
3239
  list->next = NULL;
3240
  list->file = cur_file_ptr;
3241
  list->proc = cur_proc_ptr;
3242
  list->frag = frag_now;
3243
  list->paddr = frag_now_fix ();
3244
  list->lineno = lineno;
3245
3246
  /* We don't want to merge files which have line numbers.  */
3247
  cur_file_ptr->fdr.fMerge = 0;
3248
3249
  /* A .loc directive will sometimes appear before a .ent directive,
3250
     which means that cur_proc_ptr will be NULL here.  Arrange to
3251
     patch this up.  */
3252
  if (cur_proc_ptr == NULL)
3253
    {
3254
      lineno_list_t **pl;
3255
3256
      pl = &noproc_lineno;
3257
      while (*pl != NULL)
3258
  pl = &(*pl)->next;
3259
      *pl = list;
3260
    }
3261
  else
3262
    {
3263
      last_lineno = list;
3264
      *last_lineno_ptr = list;
3265
      last_lineno_ptr = &list->next;
3266
    }
3267
}
3268
3269
/* The MIPS assembler sometimes inserts nop instructions in the
3270
   instruction stream.  When this happens, we must patch up the .loc
3271
   information so that it points to the instruction after the nop.  */
3272
3273
void
3274
ecoff_fix_loc (fragS *old_frag, unsigned long old_frag_offset)
3275
{
3276
  if (last_lineno != NULL
3277
      && last_lineno->frag == old_frag
3278
      && last_lineno->paddr == old_frag_offset)
3279
    {
3280
      last_lineno->frag = frag_now;
3281
      last_lineno->paddr = frag_now_fix ();
3282
    }
3283
}
3284

3285
/* Make sure the @stabs symbol is emitted.  */
3286
3287
static void
3288
mark_stabs (int ignore ATTRIBUTE_UNUSED)
3289
{
3290
  if (! stabs_seen)
3291
    {
3292
      /* Add a dummy @stabs symbol.  */
3293
      stabs_seen = 1;
3294
      (void) add_ecoff_symbol (stabs_symbol, st_Nil, sc_Info, NULL, 0, -1,
3295
             ECOFF_MARK_STAB (0));
3296
    }
3297
}
3298

3299
/* Parse .weakext directives.  */
3300
#ifndef TC_MIPS
3301
/* For TC_MIPS use the version in tc-mips.c.  */
3302
void
3303
ecoff_directive_weakext (int ignore ATTRIBUTE_UNUSED)
3304
{
3305
  char *name;
3306
  int c;
3307
  symbolS *symbolP;
3308
  expressionS exp;
3309
3310
  c = get_symbol_name (&name);
3311
  symbolP = symbol_find_or_make (name);
3312
  (void) restore_line_pointer (c);
3313
3314
  SKIP_WHITESPACE ();
3315
3316
  if (*input_line_pointer == ',')
3317
    {
3318
      if (S_IS_DEFINED (symbolP))
3319
  {
3320
    as_bad (_("symbol `%s' is already defined"),
3321
      S_GET_NAME (symbolP));
3322
    ignore_rest_of_line ();
3323
    return;
3324
  }
3325
3326
      ++input_line_pointer;
3327
      SKIP_WHITESPACE ();
3328
      if (! is_end_of_stmt (*input_line_pointer))
3329
  {
3330
#ifdef md_expr_init_rest
3331
    md_expr_init_rest (&exp);
3332
#endif
3333
    expression (&exp);
3334
    if (exp.X_op != O_symbol)
3335
      {
3336
        as_bad (_("bad .weakext directive"));
3337
        ignore_rest_of_line ();
3338
        return;
3339
      }
3340
    symbol_set_value_expression (symbolP, &exp);
3341
  }
3342
    }
3343
3344
  S_SET_WEAK (symbolP);
3345
3346
  demand_empty_rest_of_line ();
3347
}
3348
#endif /* not TC_MIPS */
3349

3350
/* Handle .stabs directives.  The actual parsing routine is done by a
3351
   generic routine.  This routine is called via OBJ_PROCESS_STAB.
3352
   When this is called, input_line_pointer will be pointing at the
3353
   value field of the stab.
3354
3355
   .stabs directives have five fields:
3356
  "string"  a string, encoding the type information.
3357
  code    a numeric code, defined in <stab.h>
3358
  0   a zero
3359
  desc    a zero or line number
3360
  value   a numeric value or an address.
3361
3362
    If the value is relocatable, we transform this into:
3363
  iss   points as an index into string space
3364
  value   value from lookup of the name
3365
  st    st from lookup of the name
3366
  sc    sc from lookup of the name
3367
  index   code|CODE_MASK
3368
3369
    If the value is not relocatable, we transform this into:
3370
  iss   points as an index into string space
3371
  value   value
3372
  st    st_Nil
3373
  sc    sc_Nil
3374
  index   code|CODE_MASK
3375
3376
    .stabn directives have four fields (string is null):
3377
  code    a numeric code, defined in <stab.h>
3378
  0   a zero
3379
  desc    a zero or a line number
3380
  value   a numeric value or an address.  */
3381
3382
void
3383
ecoff_stab (int what,
3384
      const char *string,
3385
      int type,
3386
      int other,
3387
      int desc)
3388
{
3389
  efdr_t *save_file_ptr = cur_file_ptr;
3390
  symbolS *sym;
3391
  symint_t value;
3392
  bfd_vma addend;
3393
  st_t st;
3394
  sc_t sc;
3395
  symint_t indx;
3396
  localsym_t *hold = NULL;
3397
3398
  ecoff_debugging_seen = 1;
3399
3400
  /* We don't handle .stabd.  */
3401
  if (what != 's' && what != 'n')
3402
    {
3403
      as_bad (_(".stab%c is not supported"), what);
3404
      return;
3405
    }
3406
3407
  /* A .stabn uses a null name, not an empty string.  */
3408
  if (what == 'n')
3409
    string = NULL;
3410
3411
  /* We ignore the other field.  */
3412
  if (other != 0)
3413
    as_warn (_(".stab%c: ignoring non-zero other field"), what);
3414
3415
  /* Make sure we have a current file.  */
3416
  if (cur_file_ptr == NULL)
3417
    {
3418
      add_file (NULL, 0, 1);
3419
      save_file_ptr = cur_file_ptr;
3420
    }
3421
3422
  /* For stabs in ECOFF, the first symbol must be @stabs.  This is a
3423
     signal to gdb.  */
3424
  if (stabs_seen == 0)
3425
    mark_stabs (0);
3426
3427
  /* Line number stabs are handled differently, since they have two
3428
     values, the line number and the address of the label.  We use the
3429
     index field (aka desc) to hold the line number, and the value
3430
     field to hold the address.  The symbol type is st_Label, which
3431
     should be different from the other stabs, so that gdb can
3432
     recognize it.  */
3433
  if (type == N_SLINE)
3434
    {
3435
      SYMR dummy_symr;
3436
      char *name;
3437
      char name_end;
3438
3439
#ifndef NO_LISTING
3440
      if (listing)
3441
  listing_source_line (desc);
3442
#endif
3443
3444
      dummy_symr.index = desc;
3445
      if (dummy_symr.index != desc)
3446
  {
3447
    as_warn (_("line number (%d) for .stab%c directive cannot fit in index field (20 bits)"),
3448
       desc, what);
3449
    return;
3450
  }
3451
3452
      name_end = get_symbol_name (&name);
3453
      sym = symbol_find_or_make (name);
3454
      (void) restore_line_pointer (name_end);
3455
3456
      value = 0;
3457
      addend = 0;
3458
      st = st_Label;
3459
      sc = sc_Text;
3460
      indx = desc;
3461
    }
3462
  else
3463
    {
3464
#ifndef NO_LISTING
3465
      if (listing && (type == N_SO || type == N_SOL))
3466
  listing_source_file (string);
3467
#endif
3468
3469
      if (ISDIGIT (*input_line_pointer)
3470
    || *input_line_pointer == '-'
3471
    || *input_line_pointer == '+')
3472
  {
3473
    st = st_Nil;
3474
    sc = sc_Nil;
3475
    sym = NULL;
3476
    value = get_absolute_expression ();
3477
    addend = 0;
3478
  }
3479
      else if (! is_name_beginner (*input_line_pointer))
3480
  {
3481
    as_warn (_("illegal .stab%c directive, bad character"), what);
3482
    return;
3483
  }
3484
      else
3485
  {
3486
    expressionS exp;
3487
3488
    sc = sc_Nil;
3489
    st = st_Nil;
3490
3491
#ifdef md_expr_init_rest
3492
    md_expr_init_rest (&exp);
3493
#endif
3494
    expression (&exp);
3495
    if (exp.X_op == O_constant)
3496
      {
3497
        sym = NULL;
3498
        value = exp.X_add_number;
3499
        addend = 0;
3500
      }
3501
    else if (exp.X_op == O_symbol)
3502
      {
3503
        sym = exp.X_add_symbol;
3504
        value = 0;
3505
        addend = exp.X_add_number;
3506
      }
3507
    else
3508
      {
3509
        sym = make_expr_symbol (&exp);
3510
        value = 0;
3511
        addend = 0;
3512
      }
3513
  }
3514
3515
      indx = ECOFF_MARK_STAB (type);
3516
    }
3517
3518
  /* Don't store the stabs symbol we are creating as the type of the
3519
     ECOFF symbol.  We want to compute the type of the ECOFF symbol
3520
     independently.  */
3521
  if (sym != NULL)
3522
    hold = symbol_get_obj (sym)->ecoff_symbol;
3523
3524
  (void) add_ecoff_symbol (string, st, sc, sym, addend, value, indx);
3525
3526
  if (sym != NULL)
3527
    symbol_get_obj (sym)->ecoff_symbol = hold;
3528
3529
  /* Restore normal file type.  */
3530
  cur_file_ptr = save_file_ptr;
3531
}
3532

3533
/* Frob an ECOFF symbol.  Small common symbols go into a special
3534
   .scommon section rather than bfd_com_section.  */
3535
3536
void
3537
ecoff_frob_symbol (symbolS *sym)
3538
{
3539
  if (S_IS_COMMON (sym)
3540
      && S_GET_VALUE (sym) > 0
3541
      && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput))
3542
    {
3543
      S_SET_SEGMENT (sym, &_bfd_ecoff_scom_section);
3544
    }
3545
3546
  /* Double check weak symbols.  */
3547
  if (S_IS_WEAK (sym))
3548
    {
3549
      if (S_IS_COMMON (sym))
3550
  as_bad (_("symbol `%s' can not be both weak and common"),
3551
    S_GET_NAME (sym));
3552
    }
3553
}
3554

3555
/* Add bytes to the symbolic information buffer.  */
3556
3557
static char *
3558
ecoff_add_bytes (char **buf,
3559
     char **bufend,
3560
     char *bufptr,
3561
     unsigned long need)
3562
{
3563
  unsigned long at;
3564
  unsigned long want;
3565
3566
  at = bufptr - *buf;
3567
  need -= *bufend - bufptr;
3568
  if (need < PAGE_SIZE)
3569
    need = PAGE_SIZE;
3570
  want = (*bufend - *buf) + need;
3571
  *buf = XRESIZEVEC (char, *buf, want);
3572
  *bufend = *buf + want;
3573
  return *buf + at;
3574
}
3575
3576
/* Adjust the symbolic information buffer to the alignment required
3577
   for the ECOFF target debugging information.  */
3578
3579
static unsigned long
3580
ecoff_padding_adjust (const struct ecoff_debug_swap *backend,
3581
          char **buf,
3582
          char **bufend,
3583
          unsigned long offset,
3584
          char **bufptrptr)
3585
{
3586
  bfd_size_type align;
3587
3588
  align = backend->debug_align;
3589
  if ((offset & (align - 1)) != 0)
3590
    {
3591
      unsigned long add;
3592
3593
      add = align - (offset & (align - 1));
3594
      if ((unsigned long) (*bufend - (*buf + offset)) < add)
3595
  (void) ecoff_add_bytes (buf, bufend, *buf + offset, add);
3596
      memset (*buf + offset, 0, add);
3597
      offset += add;
3598
      if (bufptrptr != NULL)
3599
  *bufptrptr = *buf + offset;
3600
    }
3601
3602
  return offset;
3603
}
3604
3605
/* Build the line number information.  */
3606
3607
static unsigned long
3608
ecoff_build_lineno (const struct ecoff_debug_swap *backend,
3609
        char **buf,
3610
        char **bufend,
3611
        unsigned long offset,
3612
        long *linecntptr)
3613
{
3614
  char *bufptr;
3615
  lineno_list_t *l;
3616
  lineno_list_t *last;
3617
  efdr_t *file;
3618
  proc_t *proc;
3619
  unsigned long c;
3620
  long totcount;
3621
  lineno_list_t first;
3622
  lineno_list_t *local_first_lineno = first_lineno;
3623
3624
  if (linecntptr != NULL)
3625
    *linecntptr = 0;
3626
3627
  bufptr = *buf + offset;
3628
3629
  file = NULL;
3630
  proc = NULL;
3631
  last = NULL;
3632
  c = offset;
3633
  totcount = 0;
3634
3635
  /* FIXME?  Now that MIPS embedded-PIC is gone, it may be safe to
3636
     remove this code.  */
3637
  /* For some reason the address of the first procedure is ignored
3638
     when reading line numbers.  This doesn't matter if the address of
3639
     the first procedure is 0, but when gcc is generating MIPS
3640
     embedded PIC code, it will put strings in the .text section
3641
     before the first procedure.  We cope by inserting a dummy line if
3642
     the address of the first procedure is not 0.  Hopefully this
3643
     won't screw things up too badly.
3644
3645
     Don't do this for ECOFF assembly source line numbers.  They work
3646
     without this extra attention.  */
3647
  if (debug_type != DEBUG_ECOFF
3648
      && first_proc_ptr != NULL
3649
      && local_first_lineno != NULL
3650
      && ((S_GET_VALUE (first_proc_ptr->sym->as_sym)
3651
     + bfd_section_vma (S_GET_SEGMENT (first_proc_ptr->sym->as_sym)))
3652
    != 0))
3653
    {
3654
      first.file = local_first_lineno->file;
3655
      first.proc = local_first_lineno->proc;
3656
      first.frag = &zero_address_frag;
3657
      first.paddr = 0;
3658
      first.lineno = 0;
3659
3660
      first.next = local_first_lineno;
3661
      local_first_lineno = &first;
3662
    }
3663
3664
  for (l = local_first_lineno; l != NULL; l = l->next)
3665
    {
3666
      long count;
3667
      long delta;
3668
3669
      /* Get the offset to the memory address of the next line number
3670
         (in words).  Do this first, so that we can skip ahead to the
3671
         next useful line number entry.  */
3672
      if (l->next == NULL)
3673
  {
3674
    /* We want a count of zero, but it will be decremented
3675
       before it is used.  */
3676
    count = 1;
3677
  }
3678
      else if (l->next->frag->fr_address + l->next->paddr
3679
         > l->frag->fr_address + l->paddr)
3680
  {
3681
    count = (l->next->frag->fr_address + l->next->paddr
3682
       - (l->frag->fr_address + l->paddr)) >> 2;
3683
  }
3684
      else
3685
  {
3686
    /* Don't change last, so we still get the right delta.  */
3687
    continue;
3688
  }
3689
3690
      if (l->file != file || l->proc != proc)
3691
  {
3692
    if (l->proc != proc && proc != NULL)
3693
      proc->pdr.lnHigh = last->lineno;
3694
    if (l->file != file && file != NULL)
3695
      {
3696
        file->fdr.cbLine = c - file->fdr.cbLineOffset;
3697
        file->fdr.cline = totcount + count;
3698
        if (linecntptr != NULL)
3699
    *linecntptr += totcount + count;
3700
        totcount = 0;
3701
      }
3702
3703
    if (l->file != file)
3704
      {
3705
        efdr_t *last_file = file;
3706
3707
        file = l->file;
3708
        if (last_file != NULL)
3709
    file->fdr.ilineBase
3710
      = last_file->fdr.ilineBase + last_file->fdr.cline;
3711
        else
3712
    file->fdr.ilineBase = 0;
3713
        file->fdr.cbLineOffset = c;
3714
      }
3715
    if (l->proc != proc)
3716
      {
3717
        proc = l->proc;
3718
        if (proc != NULL)
3719
    {
3720
      proc->pdr.lnLow = l->lineno;
3721
      proc->pdr.cbLineOffset = c - file->fdr.cbLineOffset;
3722
      proc->pdr.iline = totcount;
3723
    }
3724
      }
3725
3726
    last = NULL;
3727
  }
3728
3729
      totcount += count;
3730
3731
      /* Get the offset to this line number.  */
3732
      if (last == NULL)
3733
  delta = 0;
3734
      else
3735
  delta = l->lineno - last->lineno;
3736
3737
      /* Put in the offset to this line number.  */
3738
      while (delta != 0)
3739
  {
3740
    int setcount;
3741
3742
    /* 1 is added to each count read.  */
3743
    --count;
3744
    /* We can only adjust the word count by up to 15 words at a
3745
       time.  */
3746
    if (count <= 0x0f)
3747
      {
3748
        setcount = count;
3749
        count = 0;
3750
      }
3751
    else
3752
      {
3753
        setcount = 0x0f;
3754
        count -= 0x0f;
3755
      }
3756
    if (delta >= -7 && delta <= 7)
3757
      {
3758
        if (bufptr >= *bufend)
3759
    bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
3760
        *bufptr++ = setcount + (delta << 4);
3761
        delta = 0;
3762
        ++c;
3763
      }
3764
    else
3765
      {
3766
        int set;
3767
3768
        if (*bufend - bufptr < 3)
3769
    bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 3);
3770
        *bufptr++ = setcount + (8 << 4);
3771
        if (delta < -0x8000)
3772
    {
3773
      set = -0x8000;
3774
      delta += 0x8000;
3775
    }
3776
        else if (delta > 0x7fff)
3777
    {
3778
      set = 0x7fff;
3779
      delta -= 0x7fff;
3780
    }
3781
        else
3782
    {
3783
      set = delta;
3784
      delta = 0;
3785
    }
3786
        *bufptr++ = set >> 8;
3787
        *bufptr++ = set & 0xffff;
3788
        c += 3;
3789
      }
3790
  }
3791
3792
      /* Finish adjusting the count.  */
3793
      while (count > 0)
3794
  {
3795
    if (bufptr >= *bufend)
3796
      bufptr = ecoff_add_bytes (buf, bufend, bufptr, 1);
3797
    /* 1 is added to each count read.  */
3798
    --count;
3799
    if (count > 0x0f)
3800
      {
3801
        *bufptr++ = 0x0f;
3802
        count -= 0x0f;
3803
      }
3804
    else
3805
      {
3806
        *bufptr++ = count;
3807
        count = 0;
3808
      }
3809
    ++c;
3810
  }
3811
3812
      last = l;
3813
    }
3814
3815
  if (proc != NULL)
3816
    proc->pdr.lnHigh = last->lineno;
3817
  if (file != NULL)
3818
    {
3819
      file->fdr.cbLine = c - file->fdr.cbLineOffset;
3820
      file->fdr.cline = totcount;
3821
    }
3822
3823
  if (linecntptr != NULL)
3824
    *linecntptr += totcount;
3825
3826
  c = ecoff_padding_adjust (backend, buf, bufend, c, &bufptr);
3827
3828
  return c;
3829
}
3830
3831
/* Build and swap out the symbols.  */
3832
3833
static unsigned long
3834
ecoff_build_symbols (const struct ecoff_debug_swap *backend,
3835
         char **buf,
3836
         char **bufend,
3837
         unsigned long offset)
3838
{
3839
  const bfd_size_type external_sym_size = backend->external_sym_size;
3840
  void (* const swap_sym_out) (bfd *, const SYMR *, void *)
3841
    = backend->swap_sym_out;
3842
  char *sym_out;
3843
  long isym;
3844
  vlinks_t *file_link;
3845
3846
  sym_out = *buf + offset;
3847
3848
  isym = 0;
3849
3850
  /* The symbols are stored by file.  */
3851
  for (file_link = file_desc.first;
3852
       file_link != NULL;
3853
       file_link = file_link->next)
3854
    {
3855
      int ifilesym;
3856
      int fil_cnt;
3857
      efdr_t *fil_ptr;
3858
      efdr_t *fil_end;
3859
3860
      if (file_link->next == NULL)
3861
  fil_cnt = file_desc.objects_last_page;
3862
      else
3863
  fil_cnt = file_desc.objects_per_page;
3864
      fil_ptr = file_link->datum->file;
3865
      fil_end = fil_ptr + fil_cnt;
3866
      for (; fil_ptr < fil_end; fil_ptr++)
3867
  {
3868
    vlinks_t *sym_link;
3869
3870
    fil_ptr->fdr.isymBase = isym;
3871
    ifilesym = isym;
3872
    for (sym_link = fil_ptr->symbols.first;
3873
         sym_link != NULL;
3874
         sym_link = sym_link->next)
3875
      {
3876
        int sym_cnt;
3877
        localsym_t *sym_ptr;
3878
        localsym_t *sym_end;
3879
3880
        if (sym_link->next == NULL)
3881
    sym_cnt = fil_ptr->symbols.objects_last_page;
3882
        else
3883
    sym_cnt = fil_ptr->symbols.objects_per_page;
3884
        sym_ptr = sym_link->datum->sym;
3885
        sym_end = sym_ptr + sym_cnt;
3886
        for (; sym_ptr < sym_end; sym_ptr++)
3887
    {
3888
      int local;
3889
      symbolS *as_sym;
3890
      forward_t *f;
3891
3892
      know (sym_ptr->file_ptr == fil_ptr);
3893
3894
      /* If there is no associated gas symbol, then this
3895
         is a pure debugging symbol.  We have already
3896
         added the name (if any) to fil_ptr->strings.
3897
         Otherwise we must decide whether this is an
3898
         external or a local symbol (actually, it may be
3899
         both if the local provides additional debugging
3900
         information for the external).  */
3901
      local = 1;
3902
      as_sym = sym_ptr->as_sym;
3903
      if (as_sym != NULL)
3904
        {
3905
          symint_t indx;
3906
3907
          /* The value of a block start symbol is the
3908
             offset from the start of the procedure.  For
3909
             other symbols we just use the gas value (but
3910
             we must offset it by the vma of the section,
3911
             just as BFD does, because BFD will not see
3912
             this value).  */
3913
          if (sym_ptr->ecoff_sym.asym.st == st_Block
3914
        && sym_ptr->ecoff_sym.asym.sc == sc_Text)
3915
      {
3916
        symbolS *begin_sym;
3917
3918
        know (sym_ptr->proc_ptr != NULL);
3919
        begin_sym = sym_ptr->proc_ptr->sym->as_sym;
3920
        if (S_GET_SEGMENT (as_sym)
3921
            != S_GET_SEGMENT (begin_sym))
3922
          as_warn (_(".begin/.bend in different segments"));
3923
        sym_ptr->ecoff_sym.asym.value =
3924
          S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
3925
      }
3926
          else
3927
      sym_ptr->ecoff_sym.asym.value =
3928
        (S_GET_VALUE (as_sym)
3929
         + bfd_section_vma (S_GET_SEGMENT (as_sym))
3930
         + sym_ptr->addend);
3931
3932
          sym_ptr->ecoff_sym.weakext = S_IS_WEAK (as_sym);
3933
3934
          /* Set st_Proc to st_StaticProc for local
3935
       functions.  */
3936
          if (sym_ptr->ecoff_sym.asym.st == st_Proc
3937
        && S_IS_DEFINED (as_sym)
3938
        && ! S_IS_EXTERNAL (as_sym)
3939
        && ! S_IS_WEAK (as_sym))
3940
      sym_ptr->ecoff_sym.asym.st = st_StaticProc;
3941
3942
          /* Get the type and storage class based on where
3943
             the symbol actually wound up.  Traditionally,
3944
             N_LBRAC and N_RBRAC are *not* relocated.  */
3945
          indx = sym_ptr->ecoff_sym.asym.index;
3946
          if (sym_ptr->ecoff_sym.asym.st == st_Nil
3947
        && sym_ptr->ecoff_sym.asym.sc == sc_Nil
3948
        && (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
3949
            || ((ECOFF_UNMARK_STAB (indx) != N_LBRAC)
3950
          && (ECOFF_UNMARK_STAB (indx) != N_RBRAC))))
3951
      {
3952
        segT seg;
3953
        const char *segname;
3954
        st_t st;
3955
        sc_t sc;
3956
3957
        seg = S_GET_SEGMENT (as_sym);
3958
        segname = segment_name (seg);
3959
3960
        if (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
3961
            && (S_IS_EXTERNAL (as_sym)
3962
          || S_IS_WEAK (as_sym)
3963
          || ! S_IS_DEFINED (as_sym)))
3964
          {
3965
            if ((symbol_get_bfdsym (as_sym)->flags
3966
           & BSF_FUNCTION) != 0)
3967
        st = st_Proc;
3968
            else
3969
        st = st_Global;
3970
          }
3971
        else if (seg == text_section)
3972
          st = st_Label;
3973
        else
3974
          st = st_Static;
3975
3976
        if (! S_IS_DEFINED (as_sym))
3977
          {
3978
            valueT s;
3979
3980
            s = symbol_get_obj (as_sym)->ecoff_extern_size;
3981
            if (s == 0
3982
          || s > bfd_get_gp_size (stdoutput))
3983
        sc = sc_Undefined;
3984
            else
3985
        {
3986
          sc = sc_SUndefined;
3987
          sym_ptr->ecoff_sym.asym.value = s;
3988
        }
3989
#ifdef S_SET_SIZE
3990
            S_SET_SIZE (as_sym, s);
3991
#endif
3992
          }
3993
        else if (S_IS_COMMON (as_sym))
3994
          {
3995
            if (S_GET_VALUE (as_sym) > 0
3996
          && (S_GET_VALUE (as_sym)
3997
              <= bfd_get_gp_size (stdoutput)))
3998
        sc = sc_SCommon;
3999
            else
4000
        sc = sc_Common;
4001
          }
4002
        else if (seg == text_section)
4003
          sc = sc_Text;
4004
        else if (seg == data_section)
4005
          sc = sc_Data;
4006
        else if (strcmp (segname, ".rdata") == 0
4007
           || strcmp (segname, ".rodata") == 0)
4008
          sc = sc_RData;
4009
        else if (strcmp (segname, ".sdata") == 0)
4010
          sc = sc_SData;
4011
        else if (seg == bss_section)
4012
          sc = sc_Bss;
4013
        else if (strcmp (segname, ".sbss") == 0)
4014
          sc = sc_SBss;
4015
        else if (seg == bfd_abs_section_ptr)
4016
          sc = sc_Abs;
4017
        else
4018
          {
4019
            /* This must be a user named section.
4020
               This is not possible in ECOFF, but it
4021
               is in ELF.  */
4022
            sc = sc_Data;
4023
          }
4024
4025
        sym_ptr->ecoff_sym.asym.st = st;
4026
        sym_ptr->ecoff_sym.asym.sc = sc;
4027
      }
4028
4029
          /* This is just an external symbol if it is
4030
             outside a procedure and it has a type.
4031
             FIXME: g++ will generate symbols which have
4032
             different names in the debugging information
4033
             than the actual symbol.  Should we handle
4034
             them here?  */
4035
          if ((S_IS_EXTERNAL (as_sym)
4036
         || S_IS_WEAK (as_sym)
4037
         || ! S_IS_DEFINED (as_sym))
4038
        && sym_ptr->proc_ptr == NULL
4039
        && sym_ptr->ecoff_sym.asym.st != st_Nil
4040
        && ! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym))
4041
      local = 0;
4042
4043
          /* This is just an external symbol if it is a
4044
             common symbol.  */
4045
          if (S_IS_COMMON (as_sym))
4046
      local = 0;
4047
4048
          /* If an st_end symbol has an associated gas
4049
             symbol, then it is a local label created for
4050
             a .bend or .end directive.  Stabs line
4051
             numbers will have FAKE_LABEL_CHAR in the names.  */
4052
          if (local
4053
        && sym_ptr->ecoff_sym.asym.st != st_End
4054
        && strchr (sym_ptr->name, FAKE_LABEL_CHAR) == 0)
4055
      sym_ptr->ecoff_sym.asym.iss =
4056
        add_string (&fil_ptr->strings,
4057
              fil_ptr->str_hash,
4058
              sym_ptr->name,
4059
              NULL);
4060
        }
4061
4062
      /* We now know the index of this symbol; fill in
4063
         locations that have been waiting for that
4064
         information.  */
4065
      if (sym_ptr->begin_ptr != NULL)
4066
        {
4067
          localsym_t *begin_ptr;
4068
          st_t begin_type;
4069
4070
          know (local);
4071
          begin_ptr = sym_ptr->begin_ptr;
4072
          know (begin_ptr->sym_index != -1);
4073
          sym_ptr->ecoff_sym.asym.index = begin_ptr->sym_index;
4074
          if (sym_ptr->ecoff_sym.asym.sc != sc_Info)
4075
      sym_ptr->ecoff_sym.asym.iss =
4076
        begin_ptr->ecoff_sym.asym.iss;
4077
4078
          begin_type = (st_t) begin_ptr->ecoff_sym.asym.st;
4079
          if (begin_type == st_File
4080
        || begin_type == st_Block)
4081
      {
4082
        begin_ptr->ecoff_sym.asym.index =
4083
          isym - ifilesym + 1;
4084
        (*swap_sym_out) (stdoutput,
4085
             &begin_ptr->ecoff_sym.asym,
4086
             (*buf
4087
              + offset
4088
              + (begin_ptr->sym_index
4089
                 * external_sym_size)));
4090
      }
4091
          else
4092
      {
4093
        know (begin_ptr->index_ptr != NULL);
4094
        begin_ptr->index_ptr->data.isym =
4095
          isym - ifilesym + 1;
4096
      }
4097
4098
          /* The value of the symbol marking the end of a
4099
             procedure is the size of the procedure.  The
4100
             value of the symbol marking the end of a
4101
             block is the offset from the start of the
4102
             procedure to the block.  */
4103
          if (begin_type == st_Proc
4104
        || begin_type == st_StaticProc)
4105
      {
4106
        know (as_sym != NULL);
4107
        know (begin_ptr->as_sym != NULL);
4108
        if (S_GET_SEGMENT (as_sym)
4109
            != S_GET_SEGMENT (begin_ptr->as_sym))
4110
          as_warn (_(".begin/.bend in different segments"));
4111
        sym_ptr->ecoff_sym.asym.value =
4112
          (S_GET_VALUE (as_sym)
4113
           - S_GET_VALUE (begin_ptr->as_sym));
4114
4115
        /* If the size is odd, this is probably a
4116
           mips16 function; force it to be even.  */
4117
        if ((sym_ptr->ecoff_sym.asym.value & 1) != 0)
4118
          ++sym_ptr->ecoff_sym.asym.value;
4119
4120
#ifdef S_SET_SIZE
4121
        S_SET_SIZE (begin_ptr->as_sym,
4122
              sym_ptr->ecoff_sym.asym.value);
4123
#endif
4124
      }
4125
          else if (begin_type == st_Block
4126
             && sym_ptr->ecoff_sym.asym.sc != sc_Info)
4127
      {
4128
        symbolS *begin_sym;
4129
4130
        know (as_sym != NULL);
4131
        know (sym_ptr->proc_ptr != NULL);
4132
        begin_sym = sym_ptr->proc_ptr->sym->as_sym;
4133
        if (S_GET_SEGMENT (as_sym)
4134
            != S_GET_SEGMENT (begin_sym))
4135
          as_warn (_(".begin/.bend in different segments"));
4136
        sym_ptr->ecoff_sym.asym.value =
4137
          S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
4138
      }
4139
        }
4140
4141
      for (f = sym_ptr->forward_ref;
4142
           f != NULL;
4143
           f = f->next)
4144
        {
4145
          know (local);
4146
          f->ifd_ptr->data.isym = fil_ptr->file_index;
4147
          f->index_ptr->data.rndx.index = isym - ifilesym;
4148
        }
4149
4150
      if (local)
4151
        {
4152
          if ((bfd_size_type)(*bufend - sym_out) < external_sym_size)
4153
      sym_out = ecoff_add_bytes (buf, bufend,
4154
               sym_out,
4155
               external_sym_size);
4156
          (*swap_sym_out) (stdoutput, &sym_ptr->ecoff_sym.asym,
4157
               sym_out);
4158
          sym_out += external_sym_size;
4159
4160
          sym_ptr->sym_index = isym;
4161
4162
          if (sym_ptr->proc_ptr != NULL
4163
        && sym_ptr->proc_ptr->sym == sym_ptr)
4164
      sym_ptr->proc_ptr->pdr.isym = isym - ifilesym;
4165
4166
          ++isym;
4167
        }
4168
4169
      /* Record the local symbol index and file number in
4170
         case this is an external symbol.  Note that this
4171
         destroys the asym.index field.  */
4172
      if (as_sym != NULL
4173
          && symbol_get_obj (as_sym)->ecoff_symbol == sym_ptr)
4174
        {
4175
          if ((sym_ptr->ecoff_sym.asym.st == st_Proc
4176
         || sym_ptr->ecoff_sym.asym.st == st_StaticProc)
4177
        && local)
4178
      sym_ptr->ecoff_sym.asym.index = isym - ifilesym - 1;
4179
          sym_ptr->ecoff_sym.ifd = fil_ptr->file_index;
4180
4181
          /* Don't try to merge an FDR which has an
4182
             external symbol attached to it.  */
4183
          if (S_IS_EXTERNAL (as_sym) || S_IS_WEAK (as_sym))
4184
      fil_ptr->fdr.fMerge = 0;
4185
        }
4186
    }
4187
      }
4188
    fil_ptr->fdr.csym = isym - fil_ptr->fdr.isymBase;
4189
  }
4190
    }
4191
4192
  return offset + isym * external_sym_size;
4193
}
4194
4195
/* Swap out the procedure information.  */
4196
4197
static unsigned long
4198
ecoff_build_procs (const struct ecoff_debug_swap *backend,
4199
       char **buf,
4200
       char **bufend,
4201
       unsigned long offset)
4202
{
4203
  const bfd_size_type external_pdr_size = backend->external_pdr_size;
4204
  void (* const swap_pdr_out) (bfd *, const PDR *, void *)
4205
    = backend->swap_pdr_out;
4206
  char *pdr_out;
4207
  long iproc;
4208
  vlinks_t *file_link;
4209
4210
  pdr_out = *buf + offset;
4211
4212
  iproc = 0;
4213
4214
  /* The procedures are stored by file.  */
4215
  for (file_link = file_desc.first;
4216
       file_link != NULL;
4217
       file_link = file_link->next)
4218
    {
4219
      int fil_cnt;
4220
      efdr_t *fil_ptr;
4221
      efdr_t *fil_end;
4222
4223
      if (file_link->next == NULL)
4224
  fil_cnt = file_desc.objects_last_page;
4225
      else
4226
  fil_cnt = file_desc.objects_per_page;
4227
      fil_ptr = file_link->datum->file;
4228
      fil_end = fil_ptr + fil_cnt;
4229
      for (; fil_ptr < fil_end; fil_ptr++)
4230
  {
4231
    vlinks_t *proc_link;
4232
    int first;
4233
4234
    fil_ptr->fdr.ipdFirst = iproc;
4235
    first = 1;
4236
    for (proc_link = fil_ptr->procs.first;
4237
         proc_link != NULL;
4238
         proc_link = proc_link->next)
4239
      {
4240
        int prc_cnt;
4241
        proc_t *proc_ptr;
4242
        proc_t *proc_end;
4243
4244
        if (proc_link->next == NULL)
4245
    prc_cnt = fil_ptr->procs.objects_last_page;
4246
        else
4247
    prc_cnt = fil_ptr->procs.objects_per_page;
4248
        proc_ptr = proc_link->datum->proc;
4249
        proc_end = proc_ptr + prc_cnt;
4250
        for (; proc_ptr < proc_end; proc_ptr++)
4251
    {
4252
      symbolS *adr_sym;
4253
      unsigned long adr;
4254
4255
      adr_sym = proc_ptr->sym->as_sym;
4256
      adr = (S_GET_VALUE (adr_sym)
4257
       + bfd_section_vma (S_GET_SEGMENT (adr_sym)));
4258
      if (first)
4259
        {
4260
          /* This code used to force the adr of the very
4261
             first fdr to be 0.  However, the native tools
4262
             don't do that, and I can't remember why it
4263
             used to work that way, so I took it out.  */
4264
          fil_ptr->fdr.adr = adr;
4265
          first = 0;
4266
        }
4267
      proc_ptr->pdr.adr = adr - fil_ptr->fdr.adr;
4268
      if ((bfd_size_type)(*bufend - pdr_out) < external_pdr_size)
4269
        pdr_out = ecoff_add_bytes (buf, bufend,
4270
                 pdr_out,
4271
                 external_pdr_size);
4272
      (*swap_pdr_out) (stdoutput, &proc_ptr->pdr, pdr_out);
4273
      pdr_out += external_pdr_size;
4274
      ++iproc;
4275
    }
4276
      }
4277
    fil_ptr->fdr.cpd = iproc - fil_ptr->fdr.ipdFirst;
4278
  }
4279
    }
4280
4281
  return offset + iproc * external_pdr_size;
4282
}
4283
4284
/* Swap out the aux information.  */
4285
4286
static unsigned long
4287
ecoff_build_aux (const struct ecoff_debug_swap *backend,
4288
     char **buf,
4289
     char **bufend,
4290
     unsigned long offset)
4291
{
4292
  int bigendian;
4293
  union aux_ext *aux_out;
4294
  long iaux;
4295
  vlinks_t *file_link;
4296
4297
  bigendian = bfd_big_endian (stdoutput);
4298
4299
  aux_out = (union aux_ext *) (*buf + offset);
4300
4301
  iaux = 0;
4302
4303
  /* The aux entries are stored by file.  */
4304
  for (file_link = file_desc.first;
4305
       file_link != NULL;
4306
       file_link = file_link->next)
4307
    {
4308
      int fil_cnt;
4309
      efdr_t *fil_ptr;
4310
      efdr_t *fil_end;
4311
4312
      if (file_link->next == NULL)
4313
  fil_cnt = file_desc.objects_last_page;
4314
      else
4315
  fil_cnt = file_desc.objects_per_page;
4316
      fil_ptr = file_link->datum->file;
4317
      fil_end = fil_ptr + fil_cnt;
4318
      for (; fil_ptr < fil_end; fil_ptr++)
4319
  {
4320
    vlinks_t *aux_link;
4321
4322
    fil_ptr->fdr.fBigendian = bigendian;
4323
    fil_ptr->fdr.iauxBase = iaux;
4324
    for (aux_link = fil_ptr->aux_syms.first;
4325
         aux_link != NULL;
4326
         aux_link = aux_link->next)
4327
      {
4328
        int aux_cnt;
4329
        aux_t *aux_ptr;
4330
        aux_t *aux_end;
4331
4332
        if (aux_link->next == NULL)
4333
    aux_cnt = fil_ptr->aux_syms.objects_last_page;
4334
        else
4335
    aux_cnt = fil_ptr->aux_syms.objects_per_page;
4336
        aux_ptr = aux_link->datum->aux;
4337
        aux_end = aux_ptr + aux_cnt;
4338
        for (; aux_ptr < aux_end; aux_ptr++)
4339
    {
4340
      if ((unsigned long) (*bufend - (char *) aux_out)
4341
          < sizeof (union aux_ext))
4342
        aux_out = ((union aux_ext *)
4343
             ecoff_add_bytes (buf, bufend,
4344
            (char *) aux_out,
4345
            sizeof (union aux_ext)));
4346
      switch (aux_ptr->type)
4347
        {
4348
        case aux_tir:
4349
          (*backend->swap_tir_out) (bigendian,
4350
            &aux_ptr->data.ti,
4351
            &aux_out->a_ti);
4352
          break;
4353
        case aux_rndx:
4354
          (*backend->swap_rndx_out) (bigendian,
4355
             &aux_ptr->data.rndx,
4356
             &aux_out->a_rndx);
4357
          break;
4358
        case aux_dnLow:
4359
          AUX_PUT_DNLOW (bigendian, aux_ptr->data.dnLow,
4360
             aux_out);
4361
          break;
4362
        case aux_dnHigh:
4363
          AUX_PUT_DNHIGH (bigendian, aux_ptr->data.dnHigh,
4364
              aux_out);
4365
          break;
4366
        case aux_isym:
4367
          AUX_PUT_ISYM (bigendian, aux_ptr->data.isym,
4368
            aux_out);
4369
          break;
4370
        case aux_iss:
4371
          AUX_PUT_ISS (bigendian, aux_ptr->data.iss,
4372
           aux_out);
4373
          break;
4374
        case aux_width:
4375
          AUX_PUT_WIDTH (bigendian, aux_ptr->data.width,
4376
             aux_out);
4377
          break;
4378
        case aux_count:
4379
          AUX_PUT_COUNT (bigendian, aux_ptr->data.count,
4380
             aux_out);
4381
          break;
4382
        }
4383
4384
      ++aux_out;
4385
      ++iaux;
4386
    }
4387
      }
4388
    fil_ptr->fdr.caux = iaux - fil_ptr->fdr.iauxBase;
4389
  }
4390
    }
4391
4392
  return ecoff_padding_adjust (backend, buf, bufend,
4393
             offset + iaux * sizeof (union aux_ext),
4394
             NULL);
4395
}
4396
4397
/* Copy out the strings from a varray_t.  This returns the number of
4398
   bytes copied, rather than the new offset.  */
4399
4400
static unsigned long
4401
ecoff_build_strings (char **buf,
4402
         char **bufend,
4403
         unsigned long offset,
4404
         varray_t *vp)
4405
{
4406
  unsigned long istr;
4407
  char *str_out;
4408
  vlinks_t *str_link;
4409
4410
  str_out = *buf + offset;
4411
4412
  istr = 0;
4413
4414
  for (str_link = vp->first;
4415
       str_link != NULL;
4416
       str_link = str_link->next)
4417
    {
4418
      unsigned long str_cnt;
4419
4420
      if (str_link->next == NULL)
4421
  str_cnt = vp->objects_last_page;
4422
      else
4423
  str_cnt = vp->objects_per_page;
4424
4425
      if ((unsigned long)(*bufend - str_out) < str_cnt)
4426
  str_out = ecoff_add_bytes (buf, bufend, str_out, str_cnt);
4427
4428
      memcpy (str_out, str_link->datum->byte, str_cnt);
4429
      str_out += str_cnt;
4430
      istr += str_cnt;
4431
    }
4432
4433
  return istr;
4434
}
4435
4436
/* Dump out the local strings.  */
4437
4438
static unsigned long
4439
ecoff_build_ss (const struct ecoff_debug_swap *backend,
4440
    char **buf,
4441
    char **bufend,
4442
    unsigned long offset)
4443
{
4444
  long iss;
4445
  vlinks_t *file_link;
4446
4447
  iss = 0;
4448
4449
  for (file_link = file_desc.first;
4450
       file_link != NULL;
4451
       file_link = file_link->next)
4452
    {
4453
      int fil_cnt;
4454
      efdr_t *fil_ptr;
4455
      efdr_t *fil_end;
4456
4457
      if (file_link->next == NULL)
4458
  fil_cnt = file_desc.objects_last_page;
4459
      else
4460
  fil_cnt = file_desc.objects_per_page;
4461
      fil_ptr = file_link->datum->file;
4462
      fil_end = fil_ptr + fil_cnt;
4463
      for (; fil_ptr < fil_end; fil_ptr++)
4464
  {
4465
    long ss_cnt;
4466
4467
    fil_ptr->fdr.issBase = iss;
4468
    ss_cnt = ecoff_build_strings (buf, bufend, offset + iss,
4469
          &fil_ptr->strings);
4470
    fil_ptr->fdr.cbSs = ss_cnt;
4471
    iss += ss_cnt;
4472
  }
4473
    }
4474
4475
  return ecoff_padding_adjust (backend, buf, bufend, offset + iss, NULL);
4476
}
4477
4478
/* Swap out the file descriptors.  */
4479
4480
static unsigned long
4481
ecoff_build_fdr (const struct ecoff_debug_swap *backend,
4482
     char **buf,
4483
     char **bufend,
4484
     unsigned long offset)
4485
{
4486
  const bfd_size_type external_fdr_size = backend->external_fdr_size;
4487
  void (* const swap_fdr_out) (bfd *, const FDR *, void *)
4488
    = backend->swap_fdr_out;
4489
  long ifile;
4490
  char *fdr_out;
4491
  vlinks_t *file_link;
4492
4493
  ifile = 0;
4494
4495
  fdr_out = *buf + offset;
4496
4497
  for (file_link = file_desc.first;
4498
       file_link != NULL;
4499
       file_link = file_link->next)
4500
    {
4501
      int fil_cnt;
4502
      efdr_t *fil_ptr;
4503
      efdr_t *fil_end;
4504
4505
      if (file_link->next == NULL)
4506
  fil_cnt = file_desc.objects_last_page;
4507
      else
4508
  fil_cnt = file_desc.objects_per_page;
4509
      fil_ptr = file_link->datum->file;
4510
      fil_end = fil_ptr + fil_cnt;
4511
      for (; fil_ptr < fil_end; fil_ptr++)
4512
  {
4513
    if ((bfd_size_type)(*bufend - fdr_out) < external_fdr_size)
4514
      fdr_out = ecoff_add_bytes (buf, bufend, fdr_out,
4515
               external_fdr_size);
4516
    (*swap_fdr_out) (stdoutput, &fil_ptr->fdr, fdr_out);
4517
    fdr_out += external_fdr_size;
4518
    ++ifile;
4519
  }
4520
    }
4521
4522
  return offset + ifile * external_fdr_size;
4523
}
4524
4525
/* Set up the external symbols.  These are supposed to be handled by
4526
   the backend.  This routine just gets the right information and
4527
   calls a backend function to deal with it.  */
4528
4529
static void
4530
ecoff_setup_ext (void)
4531
{
4532
  symbolS *sym;
4533
4534
  for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4535
    {
4536
      if (symbol_get_obj (sym)->ecoff_symbol == NULL)
4537
  continue;
4538
4539
      /* If this is a local symbol, then force the fields to zero.  */
4540
      if (! S_IS_EXTERNAL (sym)
4541
    && ! S_IS_WEAK (sym)
4542
    && S_IS_DEFINED (sym))
4543
  {
4544
    struct localsym *lsym;
4545
4546
    lsym = symbol_get_obj (sym)->ecoff_symbol;
4547
    lsym->ecoff_sym.asym.value = 0;
4548
    lsym->ecoff_sym.asym.st = st_Nil;
4549
    lsym->ecoff_sym.asym.sc = sc_Nil;
4550
    lsym->ecoff_sym.asym.index = indexNil;
4551
  }
4552
4553
      obj_ecoff_set_ext (sym, &symbol_get_obj (sym)->ecoff_symbol->ecoff_sym);
4554
    }
4555
}
4556
4557
/* Build the ECOFF debugging information.  */
4558
4559
unsigned long
4560
ecoff_build_debug (HDRR *hdr,
4561
       char **bufp,
4562
       const struct ecoff_debug_swap *backend)
4563
{
4564
  const bfd_size_type external_pdr_size = backend->external_pdr_size;
4565
  tag_t *ptag;
4566
  tag_t *ptag_next;
4567
  efdr_t *fil_ptr;
4568
  int end_warning;
4569
  efdr_t *hold_file_ptr;
4570
  proc_t *hold_proc_ptr;
4571
  symbolS *sym;
4572
  char *buf;
4573
  char *bufend;
4574
  unsigned long offset;
4575
4576
  /* Make sure we have a file.  */
4577
  if (first_file == NULL)
4578
    add_file (NULL, 0, 1);
4579
4580
  /* Handle any top level tags.  */
4581
  for (ptag = top_tag_head->first_tag;
4582
       ptag != NULL;
4583
       ptag = ptag_next)
4584
    {
4585
      if (ptag->forward_ref != NULL)
4586
  add_unknown_tag (ptag);
4587
4588
      ptag_next = ptag->same_block;
4589
      ptag->hash_ptr->tag_ptr = ptag->same_name;
4590
      free_tag (ptag);
4591
    }
4592
4593
  free_thead (top_tag_head);
4594
4595
  /* Look through the symbols.  Add debugging information for each
4596
     symbol that has not already received it.  */
4597
  hold_file_ptr = cur_file_ptr;
4598
  hold_proc_ptr = cur_proc_ptr;
4599
  cur_proc_ptr = NULL;
4600
  for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4601
    {
4602
      if (symbol_get_obj (sym)->ecoff_symbol != NULL
4603
    || symbol_get_obj (sym)->ecoff_file == NULL
4604
    || (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0)
4605
  continue;
4606
4607
      cur_file_ptr = symbol_get_obj (sym)->ecoff_file;
4608
      add_ecoff_symbol (NULL, st_Nil, sc_Nil, sym,
4609
      0, S_GET_VALUE (sym), indexNil);
4610
    }
4611
  cur_proc_ptr = hold_proc_ptr;
4612
  cur_file_ptr = hold_file_ptr;
4613
4614
  /* Output an ending symbol for all the files.  We have to do this
4615
     here for the last file, so we may as well do it for all of the
4616
     files.  */
4617
  end_warning = 0;
4618
  for (fil_ptr = first_file;
4619
       fil_ptr != NULL;
4620
       fil_ptr = fil_ptr->next_file)
4621
    {
4622
      cur_file_ptr = fil_ptr;
4623
      while (cur_file_ptr->cur_scope != NULL
4624
       && cur_file_ptr->cur_scope->prev != NULL)
4625
  {
4626
    cur_file_ptr->cur_scope = cur_file_ptr->cur_scope->prev;
4627
    if (! end_warning && ! cur_file_ptr->fake)
4628
      {
4629
        as_warn (_("missing .end or .bend at end of file"));
4630
        end_warning = 1;
4631
      }
4632
  }
4633
      if (cur_file_ptr->cur_scope != NULL)
4634
  (void) add_ecoff_symbol (NULL, st_End, sc_Text, NULL, 0, 0, 0);
4635
    }
4636
4637
  /* Build the symbolic information.  */
4638
  offset = 0;
4639
  buf = XNEWVEC (char, PAGE_SIZE);
4640
  bufend = buf + PAGE_SIZE;
4641
4642
  /* Build the line number information.  */
4643
  hdr->cbLineOffset = offset;
4644
  offset = ecoff_build_lineno (backend, &buf, &bufend, offset,
4645
             &hdr->ilineMax);
4646
  hdr->cbLine = offset - hdr->cbLineOffset;
4647
4648
  /* We don't use dense numbers at all.  */
4649
  hdr->idnMax = 0;
4650
  hdr->cbDnOffset = 0;
4651
4652
  /* We can't build the PDR table until we have built the symbols,
4653
     because a PDR contains a symbol index.  However, we set aside
4654
     space at this point.  */
4655
  hdr->ipdMax = proc_cnt;
4656
  hdr->cbPdOffset = offset;
4657
  if ((bfd_size_type)(bufend - (buf + offset)) < proc_cnt * external_pdr_size)
4658
    (void) ecoff_add_bytes (&buf, &bufend, buf + offset,
4659
          proc_cnt * external_pdr_size);
4660
  offset += proc_cnt * external_pdr_size;
4661
4662
  /* Build the local symbols.  */
4663
  hdr->cbSymOffset = offset;
4664
  offset = ecoff_build_symbols (backend, &buf, &bufend, offset);
4665
  hdr->isymMax = (offset - hdr->cbSymOffset) / backend->external_sym_size;
4666
4667
  /* Building the symbols initializes the symbol index in the PDR's.
4668
     Now we can swap out the PDR's.  */
4669
  (void) ecoff_build_procs (backend, &buf, &bufend, hdr->cbPdOffset);
4670
4671
  /* We don't use optimization symbols.  */
4672
  hdr->ioptMax = 0;
4673
  hdr->cbOptOffset = 0;
4674
4675
  /* Swap out the auxiliary type information.  */
4676
  hdr->cbAuxOffset = offset;
4677
  offset = ecoff_build_aux (backend, &buf, &bufend, offset);
4678
  hdr->iauxMax = (offset - hdr->cbAuxOffset) / sizeof (union aux_ext);
4679
4680
  /* Copy out the local strings.  */
4681
  hdr->cbSsOffset = offset;
4682
  offset = ecoff_build_ss (backend, &buf, &bufend, offset);
4683
  hdr->issMax = offset - hdr->cbSsOffset;
4684
4685
  /* We don't use relative file descriptors.  */
4686
  hdr->crfd = 0;
4687
  hdr->cbRfdOffset = 0;
4688
4689
  /* Swap out the file descriptors.  */
4690
  hdr->cbFdOffset = offset;
4691
  offset = ecoff_build_fdr (backend, &buf, &bufend, offset);
4692
  hdr->ifdMax = (offset - hdr->cbFdOffset) / backend->external_fdr_size;
4693
4694
  /* Set up the external symbols, which are handled by the BFD back
4695
     end.  */
4696
  hdr->issExtMax = 0;
4697
  hdr->cbSsExtOffset = 0;
4698
  hdr->iextMax = 0;
4699
  hdr->cbExtOffset = 0;
4700
  ecoff_setup_ext ();
4701
4702
  know ((offset & (backend->debug_align - 1)) == 0);
4703
4704
  /* FIXME: This value should be determined from the .verstamp directive,
4705
     with reasonable defaults in config files.  */
4706
#ifdef TC_ALPHA
4707
  hdr->vstamp = 0x030b;
4708
#else
4709
  hdr->vstamp = 0x020b;
4710
#endif
4711
4712
  *bufp = buf;
4713
  return offset;
4714
}
4715

4716
/* Allocate a cluster of pages.  */
4717
4718
#ifndef MALLOC_CHECK
4719
4720
static page_type *
4721
allocate_cluster (unsigned long npages)
4722
{
4723
  page_type *value = xmalloc (npages * PAGE_USIZE);
4724
4725
#ifdef ECOFF_DEBUG
4726
  if (debug > 3)
4727
    fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value);
4728
#endif
4729
4730
  memset (value, 0, npages * PAGE_USIZE);
4731
4732
  return value;
4733
}
4734
4735
static page_type *cluster_ptr = NULL;
4736
static unsigned long pages_left = 0;
4737
4738
#endif /* MALLOC_CHECK */
4739
4740
/* Allocate one page (which is initialized to 0).  */
4741
4742
static page_type *
4743
allocate_page (void)
4744
{
4745
#ifndef MALLOC_CHECK
4746
4747
  if (pages_left == 0)
4748
    {
4749
      pages_left = MAX_CLUSTER_PAGES;
4750
      cluster_ptr = allocate_cluster (pages_left);
4751
    }
4752
4753
  pages_left--;
4754
  return cluster_ptr++;
4755
4756
#else /* MALLOC_CHECK */
4757
4758
  page_type *ptr;
4759
4760
  ptr = xmalloc (PAGE_USIZE);
4761
  memset (ptr, 0, PAGE_USIZE);
4762
  return ptr;
4763
4764
#endif /* MALLOC_CHECK */
4765
}
4766

4767
/* Allocate scoping information.  */
4768
4769
static scope_t *
4770
allocate_scope (void)
4771
{
4772
  scope_t *ptr;
4773
4774
#ifndef MALLOC_CHECK
4775
4776
  ptr = alloc_counts[alloc_type_scope].free_list.f_scope;
4777
  if (ptr != NULL)
4778
    alloc_counts[alloc_type_scope].free_list.f_scope = ptr->free;
4779
  else
4780
    {
4781
      int unallocated = alloc_counts[alloc_type_scope].unallocated;
4782
      page_type *cur_page = alloc_counts[alloc_type_scope].cur_page;
4783
4784
      if (unallocated == 0)
4785
  {
4786
    unallocated = PAGE_SIZE / sizeof (scope_t);
4787
    alloc_counts[alloc_type_scope].cur_page = cur_page = allocate_page ();
4788
    alloc_counts[alloc_type_scope].total_pages++;
4789
  }
4790
4791
      ptr = &cur_page->scope[--unallocated];
4792
      alloc_counts[alloc_type_scope].unallocated = unallocated;
4793
    }
4794
4795
#else
4796
4797
  ptr = XNEW (scope_t);
4798
4799
#endif
4800
4801
  alloc_counts[alloc_type_scope].total_alloc++;
4802
  memset (ptr, 0, sizeof (*ptr));
4803
  return ptr;
4804
}
4805
4806
/* Free scoping information.  */
4807
4808
static void
4809
free_scope (scope_t *ptr)
4810
{
4811
  alloc_counts[alloc_type_scope].total_free++;
4812
4813
#ifndef MALLOC_CHECK
4814
  ptr->free = alloc_counts[alloc_type_scope].free_list.f_scope;
4815
  alloc_counts[alloc_type_scope].free_list.f_scope = ptr;
4816
#else
4817
  free (ptr);
4818
#endif
4819
}
4820

4821
/* Allocate links for pages in a virtual array.  */
4822
4823
static vlinks_t *
4824
allocate_vlinks (void)
4825
{
4826
  vlinks_t *ptr;
4827
4828
#ifndef MALLOC_CHECK
4829
4830
  int unallocated = alloc_counts[alloc_type_vlinks].unallocated;
4831
  page_type *cur_page = alloc_counts[alloc_type_vlinks].cur_page;
4832
4833
  if (unallocated == 0)
4834
    {
4835
      unallocated = PAGE_SIZE / sizeof (vlinks_t);
4836
      alloc_counts[alloc_type_vlinks].cur_page = cur_page = allocate_page ();
4837
      alloc_counts[alloc_type_vlinks].total_pages++;
4838
    }
4839
4840
  ptr = &cur_page->vlinks[--unallocated];
4841
  alloc_counts[alloc_type_vlinks].unallocated = unallocated;
4842
4843
#else
4844
4845
  ptr = XNEW (vlinks_t);
4846
4847
#endif
4848
4849
  alloc_counts[alloc_type_vlinks].total_alloc++;
4850
  memset (ptr, 0, sizeof (*ptr));
4851
  return ptr;
4852
}
4853

4854
/* Allocate string hash buckets.  */
4855
4856
static shash_t *
4857
allocate_shash (void)
4858
{
4859
  shash_t *ptr;
4860
4861
#ifndef MALLOC_CHECK
4862
4863
  int unallocated = alloc_counts[alloc_type_shash].unallocated;
4864
  page_type *cur_page = alloc_counts[alloc_type_shash].cur_page;
4865
4866
  if (unallocated == 0)
4867
    {
4868
      unallocated = PAGE_SIZE / sizeof (shash_t);
4869
      alloc_counts[alloc_type_shash].cur_page = cur_page = allocate_page ();
4870
      alloc_counts[alloc_type_shash].total_pages++;
4871
    }
4872
4873
  ptr = &cur_page->shash[--unallocated];
4874
  alloc_counts[alloc_type_shash].unallocated = unallocated;
4875
4876
#else
4877
4878
  ptr = XNEW (shash_t);
4879
4880
#endif
4881
4882
  alloc_counts[alloc_type_shash].total_alloc++;
4883
  memset (ptr, 0, sizeof (*ptr));
4884
  return ptr;
4885
}
4886

4887
/* Allocate type hash buckets.  */
4888
4889
static thash_t *
4890
allocate_thash (void)
4891
{
4892
  thash_t *ptr;
4893
4894
#ifndef MALLOC_CHECK
4895
4896
  int unallocated = alloc_counts[alloc_type_thash].unallocated;
4897
  page_type *cur_page = alloc_counts[alloc_type_thash].cur_page;
4898
4899
  if (unallocated == 0)
4900
    {
4901
      unallocated = PAGE_SIZE / sizeof (thash_t);
4902
      alloc_counts[alloc_type_thash].cur_page = cur_page = allocate_page ();
4903
      alloc_counts[alloc_type_thash].total_pages++;
4904
    }
4905
4906
  ptr = &cur_page->thash[--unallocated];
4907
  alloc_counts[alloc_type_thash].unallocated = unallocated;
4908
4909
#else
4910
4911
  ptr = XNEW (thash_t);
4912
4913
#endif
4914
4915
  alloc_counts[alloc_type_thash].total_alloc++;
4916
  memset (ptr, 0, sizeof (*ptr));
4917
  return ptr;
4918
}
4919

4920
/* Allocate structure, union, or enum tag information.  */
4921
4922
static tag_t *
4923
allocate_tag (void)
4924
{
4925
  tag_t *ptr;
4926
4927
#ifndef MALLOC_CHECK
4928
4929
  ptr = alloc_counts[alloc_type_tag].free_list.f_tag;
4930
  if (ptr != NULL)
4931
    alloc_counts[alloc_type_tag].free_list.f_tag = ptr->free;
4932
  else
4933
    {
4934
      int unallocated = alloc_counts[alloc_type_tag].unallocated;
4935
      page_type *cur_page = alloc_counts[alloc_type_tag].cur_page;
4936
4937
      if (unallocated == 0)
4938
  {
4939
    unallocated = PAGE_SIZE / sizeof (tag_t);
4940
    alloc_counts[alloc_type_tag].cur_page = cur_page = allocate_page ();
4941
    alloc_counts[alloc_type_tag].total_pages++;
4942
  }
4943
4944
      ptr = &cur_page->tag[--unallocated];
4945
      alloc_counts[alloc_type_tag].unallocated = unallocated;
4946
    }
4947
4948
#else
4949
4950
  ptr = XNEW (tag_t);
4951
4952
#endif
4953
4954
  alloc_counts[alloc_type_tag].total_alloc++;
4955
  memset (ptr, 0, sizeof (*ptr));
4956
  return ptr;
4957
}
4958
4959
/* Free scoping information.  */
4960
4961
static void
4962
free_tag (tag_t *ptr)
4963
{
4964
  alloc_counts[alloc_type_tag].total_free++;
4965
4966
#ifndef MALLOC_CHECK
4967
  ptr->free = alloc_counts[alloc_type_tag].free_list.f_tag;
4968
  alloc_counts[alloc_type_tag].free_list.f_tag = ptr;
4969
#else
4970
  free (ptr);
4971
#endif
4972
}
4973

4974
/* Allocate forward reference to a yet unknown tag.  */
4975
4976
static forward_t *
4977
allocate_forward (void)
4978
{
4979
  forward_t *ptr;
4980
4981
#ifndef MALLOC_CHECK
4982
4983
  int unallocated = alloc_counts[alloc_type_forward].unallocated;
4984
  page_type *cur_page = alloc_counts[alloc_type_forward].cur_page;
4985
4986
  if (unallocated == 0)
4987
    {
4988
      unallocated = PAGE_SIZE / sizeof (forward_t);
4989
      alloc_counts[alloc_type_forward].cur_page = cur_page = allocate_page ();
4990
      alloc_counts[alloc_type_forward].total_pages++;
4991
    }
4992
4993
  ptr = &cur_page->forward[--unallocated];
4994
  alloc_counts[alloc_type_forward].unallocated = unallocated;
4995
4996
#else
4997
4998
  ptr = XNEW (forward_t);
4999
5000
#endif
5001
5002
  alloc_counts[alloc_type_forward].total_alloc++;
5003
  memset (ptr, 0, sizeof (*ptr));
5004
  return ptr;
5005
}
5006

5007
/* Allocate head of type hash list.  */
5008
5009
static thead_t *
5010
allocate_thead (void)
5011
{
5012
  thead_t *ptr;
5013
5014
#ifndef MALLOC_CHECK
5015
5016
  ptr = alloc_counts[alloc_type_thead].free_list.f_thead;
5017
  if (ptr != NULL)
5018
    alloc_counts[alloc_type_thead].free_list.f_thead = ptr->free;
5019
  else
5020
    {
5021
      int unallocated = alloc_counts[alloc_type_thead].unallocated;
5022
      page_type *cur_page = alloc_counts[alloc_type_thead].cur_page;
5023
5024
      if (unallocated == 0)
5025
  {
5026
    unallocated = PAGE_SIZE / sizeof (thead_t);
5027
    alloc_counts[alloc_type_thead].cur_page = cur_page = allocate_page ();
5028
    alloc_counts[alloc_type_thead].total_pages++;
5029
  }
5030
5031
      ptr = &cur_page->thead[--unallocated];
5032
      alloc_counts[alloc_type_thead].unallocated = unallocated;
5033
    }
5034
5035
#else
5036
5037
  ptr = XNEW (thead_t);
5038
5039
#endif
5040
5041
  alloc_counts[alloc_type_thead].total_alloc++;
5042
  memset (ptr, 0, sizeof (*ptr));
5043
  return ptr;
5044
}
5045
5046
/* Free scoping information.  */
5047
5048
static void
5049
free_thead (thead_t *ptr)
5050
{
5051
  alloc_counts[alloc_type_thead].total_free++;
5052
5053
#ifndef MALLOC_CHECK
5054
  ptr->free = alloc_counts[alloc_type_thead].free_list.f_thead;
5055
  alloc_counts[alloc_type_thead].free_list.f_thead = ptr;
5056
#else
5057
  free (ptr);
5058
#endif
5059
}
5060

5061
static lineno_list_t *
5062
allocate_lineno_list (void)
5063
{
5064
  lineno_list_t *ptr;
5065
5066
#ifndef MALLOC_CHECK
5067
5068
  int unallocated = alloc_counts[alloc_type_lineno].unallocated;
5069
  page_type *cur_page = alloc_counts[alloc_type_lineno].cur_page;
5070
5071
  if (unallocated == 0)
5072
    {
5073
      unallocated = PAGE_SIZE / sizeof (lineno_list_t);
5074
      alloc_counts[alloc_type_lineno].cur_page = cur_page = allocate_page ();
5075
      alloc_counts[alloc_type_lineno].total_pages++;
5076
    }
5077
5078
  ptr = &cur_page->lineno[--unallocated];
5079
  alloc_counts[alloc_type_lineno].unallocated = unallocated;
5080
5081
#else
5082
5083
  ptr = XNEW (lineno_list_t);
5084
5085
#endif
5086
5087
  alloc_counts[alloc_type_lineno].total_alloc++;
5088
  memset (ptr, 0, sizeof (*ptr));
5089
  return ptr;
5090
}
5091
5092
void
5093
ecoff_set_gp_prolog_size (int sz)
5094
{
5095
  if (cur_proc_ptr == 0)
5096
    return;
5097
5098
  cur_proc_ptr->pdr.gp_prologue = sz;
5099
  if (cur_proc_ptr->pdr.gp_prologue != sz)
5100
    {
5101
      as_warn (_("GP prologue size exceeds field size, using 0 instead"));
5102
      cur_proc_ptr->pdr.gp_prologue = 0;
5103
    }
5104
5105
  cur_proc_ptr->pdr.gp_used = 1;
5106
}
5107
5108
int
5109
ecoff_no_current_file (void)
5110
{
5111
  return cur_file_ptr == NULL;
5112
}
5113
5114
void
5115
ecoff_generate_asm_lineno (void)
5116
{
5117
  unsigned int lineno;
5118
  const char *filename;
5119
  lineno_list_t *list;
5120
5121
  filename = as_where (&lineno);
5122
5123
  if (current_stabs_filename == NULL
5124
      || filename_cmp (current_stabs_filename, filename))
5125
    add_file (filename, 0, 1);
5126
5127
  list = allocate_lineno_list ();
5128
5129
  list->next = NULL;
5130
  list->file = cur_file_ptr;
5131
  list->proc = cur_proc_ptr;
5132
  list->frag = frag_now;
5133
  list->paddr = frag_now_fix ();
5134
  list->lineno = lineno;
5135
5136
  /* We don't want to merge files which have line numbers.  */
5137
  cur_file_ptr->fdr.fMerge = 0;
5138
5139
  /* A .loc directive will sometimes appear before a .ent directive,
5140
     which means that cur_proc_ptr will be NULL here.  Arrange to
5141
     patch this up.  */
5142
  if (cur_proc_ptr == NULL)
5143
    {
5144
      lineno_list_t **pl;
5145
5146
      pl = &noproc_lineno;
5147
      while (*pl != NULL)
5148
  pl = &(*pl)->next;
5149
      *pl = list;
5150
    }
5151
  else
5152
    {
5153
      last_lineno = list;
5154
      *last_lineno_ptr = list;
5155
      last_lineno_ptr = &list->next;
5156
    }
5157
}
5158
5159
#else
5160
5161
void
5162
ecoff_generate_asm_lineno (void)
5163
0
{
5164
0
}
5165
5166
#endif /* ECOFF_DEBUGGING */