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