1 /* ECOFF object file format.
2 Copyright (C) 1993 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 good deal of it comes directly from mips-tfile.c, by Michael
8 This file is part of GAS.
10 GAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GAS; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "coff/internal.h"
26 #include "coff/mips.h"
28 #include "coff/symconst.h"
29 #include "coff/ecoff-ext.h"
30 #include "aout/stab_gnu.h"
31 #include "../bfd/libecoff.h"
35 /* Why isn't this in coff/sym.h? */
36 #define ST_RFDESCAPE 0xfff
38 /* The ECOFF file format uses COFF style sections, but with a unique
39 debugging format. We just build generic BFD sections since BFD
40 knows how to write them out. The debugging format, however, we
41 must construct here; all BFD knows at the moment is to write it out
42 as a large block of data.
44 We support both COFF style debugging and stabs debugging (the stabs
45 symbols are encapsulated in COFF symbols). This should let us
46 handle anything the compiler might throw at us. Parsing the COFF
47 and stabs debugging information is similar to work done by COFF and
48 a.out targets, but since the result is completely different the
49 code is not shared. */
51 /* Here is a brief description of the MIPS ECOFF symbol table, by
52 Michael Meissner. The MIPS symbol table has the following pieces:
58 +-- Dense number table
66 +-- Relative file descriptors
78 The symbolic header points to each of the other tables, and also
79 contains the number of entries. It also contains a magic number
80 and MIPS compiler version number, such as 2.0.
82 The auxiliary table is a series of 32 bit integers, that are
83 referenced as needed from the local symbol table. Unlike standard
84 COFF, the aux. information does not follow the symbol that uses
85 it, but rather is a separate table. In theory, this would allow
86 the MIPS compilers to collapse duplicate aux. entries, but I've not
87 noticed this happening with the 1.31 compiler suite. The different
88 types of aux. entries are:
90 1) dnLow: Low bound on array dimension.
92 2) dnHigh: High bound on array dimension.
94 3) isym: Index to the local symbol which is the start of the
95 function for the end of function first aux. entry.
97 4) width: Width of structures and bitfields.
99 5) count: Count of ranges for variant part.
101 6) rndx: A relative index into the symbol table. The relative
102 index field has two parts: rfd which is a pointer into the
103 relative file index table or ST_RFDESCAPE which says the next
104 aux. entry is the file number, and index: which is the pointer
105 into the local symbol within a given file table. This is for
106 things like references to types defined in another file.
108 7) Type information: This is like the COFF type bits, except it
109 is 32 bits instead of 16; they still have room to add new
110 basic types; and they can handle more than 6 levels of array,
111 pointer, function, etc. Each type information field contains
112 the following structure members:
114 a) fBitfield: a bit that says this is a bitfield, and the
115 size in bits follows as the next aux. entry.
117 b) continued: a bit that says the next aux. entry is a
118 continuation of the current type information (in case
119 there are more than 6 levels of array/ptr/function).
121 c) bt: an integer containing the base type before adding
122 array, pointer, function, etc. qualifiers. The
123 current base types that I have documentation for are:
126 btAdr -- address - integer same size as ptr
128 btUChar -- unsigned character
130 btUShort -- unsigned short
132 btUInt -- unsigned int
134 btULong -- unsigned long
135 btFloat -- float (real)
136 btDouble -- Double (real)
137 btStruct -- Structure (Record)
138 btUnion -- Union (variant)
140 btTypedef -- defined via a typedef isymRef
141 btRange -- subrange of int
143 btComplex -- fortran complex
144 btDComplex -- fortran double complex
145 btIndirect -- forward or unnamed typedef
146 btFixedDec -- Fixed Decimal
147 btFloatDec -- Float Decimal
148 btString -- Varying Length Character String
149 btBit -- Aligned Bit String
151 btVoid -- Void (MIPS cc revision >= 2.00)
153 d) tq0 - tq5: type qualifier fields as needed. The
154 current type qualifier fields I have documentation for
157 tqNil -- no more qualifiers
161 tqFar -- 8086 far pointers
165 The dense number table is used in the front ends, and disappears by
166 the time the .o is created.
168 With the 1.31 compiler suite, the optimization symbols don't seem
169 to be used as far as I can tell.
171 The linker is the first entity that creates the relative file
172 descriptor table, and I believe it is used so that the individual
173 file table pointers don't have to be rewritten when the objects are
174 merged together into the program file.
176 Unlike COFF, the basic symbol & string tables are split into
177 external and local symbols/strings. The relocation information
178 only goes off of the external symbol table, and the debug
179 information only goes off of the internal symbol table. The
180 external symbols can have links to an appropriate file index and
181 symbol within the file to give it the appropriate type information.
182 Because of this, the external symbols are actually larger than the
183 internal symbols (to contain the link information), and contain the
184 local symbol structure as a member, though this member is not the
185 first member of the external symbol structure (!). I suspect this
186 split is to make strip easier to deal with.
188 Each file table has offsets for where the line numbers, local
189 strings, local symbols, and procedure table starts from within the
190 global tables, and the indexs are reset to 0 for each of those
193 The procedure table contains the binary equivalents of the .ent
194 (start of the function address), .frame (what register is the
195 virtual frame pointer, constant offset from the register to obtain
196 the VFP, and what register holds the return address), .mask/.fmask
197 (bitmask of saved registers, and where the first register is stored
198 relative to the VFP) assembler directives. It also contains the
199 low and high bounds of the line numbers if debugging is turned on.
201 The line number table is a compressed form of the normal COFF line
202 table. Each line number entry is either 1 or 3 bytes long, and
203 contains a signed delta from the previous line, and an unsigned
204 count of the number of instructions this statement takes.
206 The local symbol table contains the following fields:
208 1) iss: index to the local string table giving the name of the
211 2) value: value of the symbol (address, register number, etc.).
213 3) st: symbol type. The current symbol types are:
215 stNil -- Nuthin' special
216 stGlobal -- external symbol
218 stParam -- procedure argument
219 stLocal -- local variable
221 stProc -- External Procedure
222 stBlock -- beginning of block
223 stEnd -- end (of anything)
224 stMember -- member (of anything)
225 stTypedef -- type definition
227 stRegReloc -- register relocation
228 stForward -- forwarding address
229 stStaticProc -- Static procedure
232 4) sc: storage class. The current storage classes are:
234 scText -- text symbol
235 scData -- initialized data symbol
236 scBss -- un-initialized data symbol
237 scRegister -- value of symbol is register number
238 scAbs -- value of symbol is absolute
239 scUndefined -- who knows?
240 scCdbLocal -- variable's value is IN se->va.??
241 scBits -- this is a bit field
242 scCdbSystem -- value is IN debugger's address space
243 scRegImage -- register value saved on stack
244 scInfo -- symbol contains debugger information
245 scUserStruct -- addr in struct user for current process
246 scSData -- load time only small data
247 scSBss -- load time only small common
248 scRData -- load time only read only data
249 scVar -- Var parameter (fortranpascal)
250 scCommon -- common variable
251 scSCommon -- small common
252 scVarRegister -- Var parameter in a register
253 scVariant -- Variant record
254 scSUndefined -- small undefined(external) data
255 scInit -- .init section symbol
257 5) index: pointer to a local symbol or aux. entry.
261 For the following program:
266 printf("Hello World!\n");
270 Mips-tdump produces the following information:
275 timestamp 645311799, Wed Jun 13 17:16:39 1990
276 symbolic header offset 284
277 symbolic header size 96
281 Symbolic header, magic number = 0x7009, vstamp = 1.31:
283 Info Offset Number Bytes
284 ==== ====== ====== =====
286 Line numbers 380 4 4 [13]
288 Procedures Tables 384 1 52
289 Local Symbols 436 16 192
290 Optimization Symbols 0 0 0
291 Auxiliary Symbols 628 39 156
292 Local Strings 784 80 80
293 External Strings 864 144 144
294 File Tables 1008 2 144
296 External Symbols 1152 20 320
300 Name index = 1 Readin = No
301 Merge = No Endian = LITTLE
302 Debug level = G2 Language = C
305 Info Start Number Size Offset
306 ==== ===== ====== ==== ======
307 Local strings 0 15 15 784
308 Local symbols 0 6 72 436
309 Line numbers 0 13 13 380
310 Optimization symbols 0 0 0 0
311 Procedures 0 1 52 384
312 Auxiliary symbols 0 14 56 628
313 Relative Files 0 0 0 0
315 There are 6 local symbols, starting at 436
317 Symbol# 0: "hello2.c"
320 Storage class = Text Index = 6
321 Symbol type = File Value = 0
327 Storage class = Text Index = 12
328 Symbol type = Proc Value = 0
333 Storage class = Text Index = 4
334 Symbol type = Block Value = 8
339 Storage class = Text Index = 2
340 Symbol type = End Value = 28
345 Storage class = Text Index = 1
346 Symbol type = End Value = 52
348 Symbol# 5: "hello2.c"
351 Storage class = Text Index = 0
352 Symbol type = End Value = 0
354 There are 14 auxiliary table entries, starting at 628.
356 * #0 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
357 * #1 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
358 * #2 8, [ 8/ 0], [ 2 0:0 0:0:0:0:0:0]
359 * #3 16, [ 16/ 0], [ 4 0:0 0:0:0:0:0:0]
360 * #4 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
361 * #5 32, [ 32/ 0], [ 8 0:0 0:0:0:0:0:0]
362 * #6 40, [ 40/ 0], [10 0:0 0:0:0:0:0:0]
363 * #7 44, [ 44/ 0], [11 0:0 0:0:0:0:0:0]
364 * #8 12, [ 12/ 0], [ 3 0:0 0:0:0:0:0:0]
365 * #9 20, [ 20/ 0], [ 5 0:0 0:0:0:0:0:0]
366 * #10 28, [ 28/ 0], [ 7 0:0 0:0:0:0:0:0]
367 * #11 36, [ 36/ 0], [ 9 0:0 0:0:0:0:0:0]
368 #12 5, [ 5/ 0], [ 1 1:0 0:0:0:0:0:0]
369 #13 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
371 There are 1 procedure descriptor entries, starting at 0.
373 Procedure descriptor 0:
374 Name index = 10 Name = "main"
375 .mask 0x80000000,-4 .fmask 0x00000000,0
377 Opt. start = -1 Symbols start = 1
378 First line # = 3 Last line # = 6
379 Line Offset = 0 Address = 0x00000000
381 There are 4 bytes holding line numbers, starting at 380.
382 Line 3, delta 0, count 2
383 Line 4, delta 1, count 3
384 Line 5, delta 1, count 2
385 Line 6, delta 1, count 6
387 File #1, "/usr/include/stdio.h"
389 Name index = 1 Readin = No
390 Merge = Yes Endian = LITTLE
391 Debug level = G2 Language = C
394 Info Start Number Size Offset
395 ==== ===== ====== ==== ======
396 Local strings 15 65 65 799
397 Local symbols 6 10 120 508
398 Line numbers 0 0 0 380
399 Optimization symbols 0 0 0 0
401 Auxiliary symbols 14 25 100 684
402 Relative Files 0 0 0 0
404 There are 10 local symbols, starting at 442
406 Symbol# 0: "/usr/include/stdio.h"
409 Storage class = Text Index = 10
410 Symbol type = File Value = 0
415 Storage class = Info Index = 9
416 Symbol type = Block Value = 20
421 Storage class = Info Index = 4
422 Symbol type = Member Value = 0
427 Storage class = Info Index = 15
428 Symbol type = Member Value = 32
433 Storage class = Info Index = 16
434 Symbol type = Member Value = 64
439 Storage class = Info Index = 4
440 Symbol type = Member Value = 96
445 Storage class = Info Index = 3
446 Symbol type = Member Value = 128
451 Storage class = Info Index = 2
452 Symbol type = Member Value = 144
457 Storage class = Info Index = 1
458 Symbol type = End Value = 0
460 Symbol# 9: "/usr/include/stdio.h"
463 Storage class = Text Index = 0
464 Symbol type = End Value = 0
466 There are 25 auxiliary table entries, starting at 642.
468 * #14 -1, [4095/1048575], [63 1:1 f:f:f:f:f:f]
469 #15 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
470 #16 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
471 * #17 196656, [ 48/ 48], [12 0:0 3:0:0:0:0:0]
472 * #18 8191, [4095/ 1], [63 1:1 0:0:0:0:f:1]
473 * #19 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
474 * #20 20479, [4095/ 4], [63 1:1 0:0:0:0:f:4]
475 * #21 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
476 * #22 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
477 * #23 2, [ 2/ 0], [ 0 0:1 0:0:0:0:0:0]
478 * #24 160, [ 160/ 0], [40 0:0 0:0:0:0:0:0]
479 * #25 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
480 * #26 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
481 * #27 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
482 * #28 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
483 * #29 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
484 * #30 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
485 * #31 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
486 * #32 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
487 * #33 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
488 * #34 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
489 * #35 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
490 * #36 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
491 * #37 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
492 * #38 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
494 There are 0 procedure descriptor entries, starting at 1.
496 There are 20 external symbols, starting at 1152
499 Type = array [3 {160}] of struct _iobuf { ifd = 1, index = 1 }
500 String index = 0 Ifd = 1
501 Storage class = Nil Index = 17
502 Symbol type = Global Value = 60
505 String index = 5 Ifd = 1
506 Storage class = Nil Index = 1048575
507 Symbol type = Proc Value = 0
510 String index = 11 Ifd = 1
511 Storage class = Nil Index = 1048575
512 Symbol type = Proc Value = 0
515 String index = 18 Ifd = 1
516 Storage class = Nil Index = 1048575
517 Symbol type = Proc Value = 0
520 String index = 26 Ifd = 1
521 Storage class = Nil Index = 1048575
522 Symbol type = Proc Value = 0
525 String index = 32 Ifd = 1
526 Storage class = Nil Index = 1048575
527 Symbol type = Proc Value = 0
530 String index = 40 Ifd = 1
531 Storage class = Nil Index = 1048575
532 Symbol type = Proc Value = 0
535 String index = 46 Ifd = 1
536 Storage class = Nil Index = 1048575
537 Symbol type = Proc Value = 0
540 String index = 53 Ifd = 1
541 Storage class = Nil Index = 1048575
542 Symbol type = Proc Value = 0
544 Symbol# 9: "setbuffer"
545 String index = 60 Ifd = 1
546 Storage class = Nil Index = 1048575
547 Symbol type = Proc Value = 0
549 Symbol# 10: "setlinebuf"
550 String index = 70 Ifd = 1
551 Storage class = Nil Index = 1048575
552 Symbol type = Proc Value = 0
555 String index = 81 Ifd = 1
556 Storage class = Nil Index = 1048575
557 Symbol type = Proc Value = 0
560 String index = 87 Ifd = 1
561 Storage class = Nil Index = 1048575
562 Symbol type = Proc Value = 0
564 Symbol# 13: "ctermid"
565 String index = 92 Ifd = 1
566 Storage class = Nil Index = 1048575
567 Symbol type = Proc Value = 0
569 Symbol# 14: "cuserid"
570 String index = 100 Ifd = 1
571 Storage class = Nil Index = 1048575
572 Symbol type = Proc Value = 0
574 Symbol# 15: "tempnam"
575 String index = 108 Ifd = 1
576 Storage class = Nil Index = 1048575
577 Symbol type = Proc Value = 0
580 String index = 116 Ifd = 1
581 Storage class = Nil Index = 1048575
582 Symbol type = Proc Value = 0
584 Symbol# 17: "sprintf"
585 String index = 123 Ifd = 1
586 Storage class = Nil Index = 1048575
587 Symbol type = Proc Value = 0
591 String index = 131 Ifd = 0
592 Storage class = Text Index = 1
593 Symbol type = Proc Value = 0
596 String index = 136 Ifd = 0
597 Storage class = Undefined Index = 1048575
598 Symbol type = Proc Value = 0
600 The following auxiliary table entries were unused:
604 #3 16 0x00000010 short
606 #5 32 0x00000020 long
607 #6 40 0x00000028 float
608 #7 44 0x0000002c double
609 #8 12 0x0000000c unsigned char
610 #9 20 0x00000014 unsigned short
611 #10 28 0x0000001c unsigned int
612 #11 36 0x00000024 unsigned long
613 #14 0 0x00000000 void
614 #15 24 0x00000018 int
615 #19 32 0x00000020 long
616 #20 40 0x00000028 float
617 #21 44 0x0000002c double
618 #22 12 0x0000000c unsigned char
619 #23 20 0x00000014 unsigned short
620 #24 28 0x0000001c unsigned int
621 #25 36 0x00000024 unsigned long
622 #26 48 0x00000030 struct no name { ifd = -1, index = 1048575 }
625 /* Redefinition of of storage classes as an enumeration for better
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 */
655 /* Redefinition of symbol type. */
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 */
681 /* Redefinition of type qualifiers. */
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 */
693 /* Redefinition of basic types. */
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 */
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. */
735 /* Types of different sized allocation requests. */
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 */
750 /* Types of auxiliary type information. */
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 */
762 /* Structures to provide n-number of virtual arrays, each of which can
763 grow linearly, and which are written in the object file as
764 sequential pages. On systems with a BSD malloc, the
765 MAX_CLUSTER_PAGES should be 1 less than a power of two, since
766 malloc adds it's overhead, and rounds up to the next power of 2.
767 Pages are linked together via a linked list.
769 If PAGE_SIZE is > 4096, the string length in the shash_t structure
770 can't be represented (assuming there are strings > 4096 bytes). */
773 #define PAGE_SIZE 4096 /* size of varray pages */
776 #define PAGE_USIZE ((unsigned long) PAGE_SIZE)
779 #ifndef MAX_CLUSTER_PAGES /* # pages to get from system */
780 #define MAX_CLUSTER_PAGES 63
784 /* Linked list connecting separate page allocations. */
785 typedef struct vlinks {
786 struct vlinks *prev; /* previous set of pages */
787 struct vlinks *next; /* next set of pages */
788 union page *datum; /* start of page */
789 unsigned long start_index; /* starting index # of page */
793 /* Virtual array header. */
794 typedef struct varray {
795 vlinks_t *first; /* first page link */
796 vlinks_t *last; /* last page link */
797 unsigned long num_allocated; /* # objects allocated */
798 unsigned short object_size; /* size in bytes of each object */
799 unsigned short objects_per_page; /* # objects that can fit on a page */
800 unsigned short objects_last_page; /* # objects allocated on last page */
804 #define OBJECTS_PER_PAGE(type) (PAGE_SIZE / sizeof (type))
806 #define OBJECTS_PER_PAGE(type) ((sizeof (type) > 1) ? 1 : PAGE_SIZE)
809 #define INIT_VARRAY(type) { /* macro to initialize a varray */ \
810 (vlinks_t *)0, /* first */ \
811 (vlinks_t *)0, /* last */ \
812 0, /* num_allocated */ \
813 sizeof (type), /* object_size */ \
814 OBJECTS_PER_PAGE (type), /* objects_per_page */ \
815 OBJECTS_PER_PAGE (type), /* objects_last_page */ \
819 /* Master type for indexes within the symbol table. */
820 typedef unsigned long symint_t;
823 /* Linked list support for nested scopes (file, block, structure, etc.). */
824 typedef struct scope {
825 struct scope *prev; /* previous scope level */
826 struct scope *free; /* free list pointer */
827 struct localsym *lsym; /* pointer to local symbol node */
828 st_t type; /* type of the node */
832 /* For a local symbol we store a gas symbol as well as the debugging
833 information we generate. The gas symbol will be NULL if this is
834 only a debugging symbol. */
835 typedef struct localsym {
836 const char *name; /* symbol name */
837 symbolS *as_sym; /* symbol as seen by gas */
838 struct efdr *file_ptr; /* file pointer */
839 struct ecoff_proc *proc_ptr; /* proc pointer */
840 struct localsym *begin_ptr; /* symbol at start of block */
841 struct ecoff_aux *index_ptr; /* index value to be filled in */
842 struct forward *forward_ref; /* forward references to this symbol */
843 long sym_index; /* final symbol index */
844 SYMR ecoff_sym; /* ECOFF debugging symbol */
848 /* For aux information we keep the type and the data. */
849 typedef struct ecoff_aux {
850 enum aux_type type; /* aux type */
851 AUXU data; /* aux data */
854 /* For a procedure we store the gas symbol as well as the PDR
855 debugging information. */
856 typedef struct ecoff_proc {
857 localsym_t *sym; /* associated symbol */
858 PDR pdr; /* ECOFF debugging info */
861 /* Number of proc_t structures allocated. */
862 static unsigned long proc_cnt;
865 /* Forward reference list for tags referenced, but not yet defined. */
866 typedef struct forward {
867 struct forward *next; /* next forward reference */
868 struct forward *free; /* free list pointer */
869 aux_t *ifd_ptr; /* pointer to store file index */
870 aux_t *index_ptr; /* pointer to store symbol index */
874 /* Linked list support for tags. The first tag in the list is always
875 the current tag for that block. */
877 struct tag *free; /* free list pointer */
878 struct shash *hash_ptr; /* pointer to the hash table head */
879 struct tag *same_name; /* tag with same name in outer scope */
880 struct tag *same_block; /* next tag defined in the same block. */
881 struct forward *forward_ref; /* list of forward references */
882 bt_t basic_type; /* bt_Struct, bt_Union, or bt_Enum */
883 symint_t ifd; /* file # tag defined in */
884 localsym_t *sym; /* file's local symbols */
888 /* Head of a block's linked list of tags. */
889 typedef struct thead {
890 struct thead *prev; /* previous block */
891 struct thead *free; /* free list pointer */
892 struct tag *first_tag; /* first tag in block defined */
896 /* Union containing pointers to each the small structures which are freed up. */
897 typedef union small_free {
898 scope_t *f_scope; /* scope structure */
899 thead_t *f_thead; /* tag head structure */
900 tag_t *f_tag; /* tag element structure */
901 forward_t *f_forward; /* forward tag reference */
905 /* String hash table entry. */
907 typedef struct shash {
908 char *string; /* string we are hashing */
909 symint_t indx; /* index within string table */
910 EXTR *esym_ptr; /* global symbol pointer */
911 localsym_t *sym_ptr; /* local symbol pointer */
912 localsym_t *end_ptr; /* symbol pointer to end block */
913 tag_t *tag_ptr; /* tag pointer */
914 proc_t *proc_ptr; /* procedure descriptor pointer */
918 /* Type hash table support. The size of the hash table must fit
919 within a page with the other extended file descriptor information.
920 Because unique types which are hashed are fewer in number than
921 strings, we use a smaller hash value. */
926 #define THASH_SIZE 113
929 typedef struct thash {
930 struct thash *next; /* next hash value */
931 AUXU type; /* type we are hashing */
932 symint_t indx; /* index within string table */
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 symint_t void_type; /* aux. pointer to 'void' type */
943 symint_t int_type; /* aux. pointer to 'int' type */
944 scope_t *cur_scope; /* current nested scopes */
945 symint_t file_index; /* current file number */
946 int nested_scopes; /* # nested scopes */
947 varray_t strings; /* local strings */
948 varray_t symbols; /* local symbols */
949 varray_t procs; /* procedures */
950 varray_t aux_syms; /* auxiliary symbols */
951 struct efdr *next_file; /* next file descriptor */
952 /* string/type hash tables */
953 struct hash_control *str_hash; /* string hash table */
954 thash_t *thash_head[THASH_SIZE];
957 /* Pre-initialized extended file structure. */
958 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 #ifdef TARGET_BYTES_BIG_ENDIAN
981 1, /* fBigendian: if 1, compiled on big endian machine */
983 0, /* fBigendian: if 1, compiled on big endian machine */
985 GLEVEL_2, /* glevel: level this file was compiled with */
986 0, /* reserved: reserved for future use */
987 0, /* cbLineOffset: byte offset from header for this file ln's */
988 0, /* cbLine: size of lines for this file */
991 (FDR *)0, /* orig_fdr: original file header pointer */
992 (char *)0, /* name: pointer to filename */
993 0, /* void_type: ptr to aux node for void type */
994 0, /* int_type: ptr to aux node for int type */
995 (scope_t *)0, /* cur_scope: current scope being processed */
996 0, /* file_index: current file # */
997 0, /* nested_scopes: # nested scopes */
998 INIT_VARRAY (char), /* strings: local string varray */
999 INIT_VARRAY (localsym_t), /* symbols: local symbols varray */
1000 INIT_VARRAY (proc_t), /* procs: procedure varray */
1001 INIT_VARRAY (aux_t), /* aux_syms: auxiliary symbols varray */
1003 (struct efdr *)0, /* next_file: next file structure */
1005 (struct hash_control *)0, /* str_hash: string hash table */
1006 { 0 }, /* thash_head: type hash table */
1010 static efdr_t *first_file; /* first file descriptor */
1011 static efdr_t **last_file_ptr = &first_file; /* file descriptor tail */
1014 /* Line number information is kept in a list until the assembly is
1016 typedef struct lineno_list {
1017 struct lineno_list *next; /* next element in list */
1018 efdr_t *file; /* file this line is in */
1019 proc_t *proc; /* procedure this line is in */
1020 fragS *frag; /* fragment this line number is in */
1021 unsigned long paddr; /* offset within fragment */
1022 long lineno; /* actual line number */
1025 static lineno_list_t *first_lineno;
1026 static lineno_list_t **last_lineno_ptr = &first_lineno;
1028 /* Sometimes there will be some .loc statements before a .ent. We
1029 keep them in this list so that we can fill in the procedure pointer
1030 after we see the .ent. */
1031 static lineno_list_t *noproc_lineno;
1033 /* Union of various things that are held in pages. */
1034 typedef union page {
1035 char byte [ PAGE_SIZE ];
1036 unsigned char ubyte [ PAGE_SIZE ];
1037 efdr_t file [ PAGE_SIZE / sizeof (efdr_t) ];
1038 FDR ofile [ PAGE_SIZE / sizeof (FDR) ];
1039 proc_t proc [ PAGE_SIZE / sizeof (proc_t) ];
1040 localsym_t sym [ PAGE_SIZE / sizeof (localsym_t) ];
1041 aux_t aux [ PAGE_SIZE / sizeof (aux_t) ];
1042 DNR dense [ PAGE_SIZE / sizeof (DNR) ];
1043 scope_t scope [ PAGE_SIZE / sizeof (scope_t) ];
1044 vlinks_t vlinks [ PAGE_SIZE / sizeof (vlinks_t) ];
1045 shash_t shash [ PAGE_SIZE / sizeof (shash_t) ];
1046 thash_t thash [ PAGE_SIZE / sizeof (thash_t) ];
1047 tag_t tag [ PAGE_SIZE / sizeof (tag_t) ];
1048 forward_t forward [ PAGE_SIZE / sizeof (forward_t) ];
1049 thead_t thead [ PAGE_SIZE / sizeof (thead_t) ];
1050 lineno_list_t lineno [ PAGE_SIZE / sizeof (lineno_list_t) ];
1054 /* Structure holding allocation information for small sized structures. */
1055 typedef struct alloc_info {
1056 char *alloc_name; /* name of this allocation type (must be first) */
1057 page_t *cur_page; /* current page being allocated from */
1058 small_free_t free_list; /* current free list if any */
1059 int unallocated; /* number of elements unallocated on page */
1060 int total_alloc; /* total number of allocations */
1061 int total_free; /* total number of frees */
1062 int total_pages; /* total number of pages allocated */
1066 /* Type information collected together. */
1067 typedef struct type_info {
1068 bt_t basic_type; /* basic type */
1069 int orig_type; /* original COFF-based type */
1070 int num_tq; /* # type qualifiers */
1071 int num_dims; /* # dimensions */
1072 int num_sizes; /* # sizes */
1073 int extra_sizes; /* # extra sizes not tied with dims */
1074 tag_t * tag_ptr; /* tag pointer */
1075 int bitfield; /* symbol is a bitfield */
1076 tq_t type_qualifiers[N_TQ]; /* type qualifiers (ptr, func, array)*/
1077 symint_t dimensions [N_TQ]; /* dimensions for each array */
1078 symint_t sizes [N_TQ+2]; /* sizes of each array slice + size of
1079 struct/union/enum + bitfield size */
1082 /* Pre-initialized type_info struct. */
1083 static const type_info_t type_info_init = {
1084 bt_Nil, /* basic type */
1085 T_NULL, /* original COFF-based type */
1086 0, /* # type qualifiers */
1087 0, /* # dimensions */
1089 0, /* sizes not tied with dims */
1090 NULL, /* ptr to tag */
1092 { /* type qualifiers */
1120 /* Global hash table for the tags table and global table for file
1123 static varray_t file_desc = INIT_VARRAY (efdr_t);
1125 static struct hash_control *tag_hash;
1127 /* Static types for int and void. Also, remember the last function's
1128 type (which is set up when we encounter the declaration for the
1129 function, and used when the end block for the function is emitted. */
1131 static type_info_t int_type_info;
1132 static type_info_t void_type_info;
1133 static type_info_t last_func_type_info;
1134 static symbolS *last_func_sym_value;
1137 /* Convert COFF basic type to ECOFF basic type. The T_NULL type
1138 really should use bt_Void, but this causes the current ecoff GDB to
1139 issue unsupported type messages, and the Ultrix 4.00 dbx (aka MIPS
1140 2.0) doesn't understand it, even though the compiler generates it.
1141 Maybe this will be fixed in 2.10 or 2.20 of the MIPS compiler
1142 suite, but for now go with what works.
1144 It would make sense for the .type and .scl directives to use the
1145 ECOFF numbers directly, rather than using the COFF numbers and
1146 mapping them. Unfortunately, this is historically what mips-tfile
1147 expects, and changing gcc now would be a considerable pain (the
1148 native compiler generates debugging information internally, rather
1149 than via the assembler, so it will never use .type or .scl). */
1151 static const bt_t map_coff_types[] = {
1152 bt_Nil, /* T_NULL */
1154 bt_Char, /* T_CHAR */
1155 bt_Short, /* T_SHORT */
1157 bt_Long, /* T_LONG */
1158 bt_Float, /* T_FLOAT */
1159 bt_Double, /* T_DOUBLE */
1160 bt_Struct, /* T_STRUCT */
1161 bt_Union, /* T_UNION */
1162 bt_Enum, /* T_ENUM */
1163 bt_Enum, /* T_MOE */
1164 bt_UChar, /* T_UCHAR */
1165 bt_UShort, /* T_USHORT */
1166 bt_UInt, /* T_UINT */
1167 bt_ULong /* T_ULONG */
1170 /* Convert COFF storage class to ECOFF storage class. */
1171 static const sc_t map_coff_storage[] = {
1172 sc_Nil, /* 0: C_NULL */
1173 sc_Abs, /* 1: C_AUTO auto var */
1174 sc_Undefined, /* 2: C_EXT external */
1175 sc_Data, /* 3: C_STAT static */
1176 sc_Register, /* 4: C_REG register */
1177 sc_Undefined, /* 5: C_EXTDEF ??? */
1178 sc_Text, /* 6: C_LABEL label */
1179 sc_Text, /* 7: C_ULABEL user label */
1180 sc_Info, /* 8: C_MOS member of struct */
1181 sc_Abs, /* 9: C_ARG argument */
1182 sc_Info, /* 10: C_STRTAG struct tag */
1183 sc_Info, /* 11: C_MOU member of union */
1184 sc_Info, /* 12: C_UNTAG union tag */
1185 sc_Info, /* 13: C_TPDEF typedef */
1186 sc_Data, /* 14: C_USTATIC ??? */
1187 sc_Info, /* 15: C_ENTAG enum tag */
1188 sc_Info, /* 16: C_MOE member of enum */
1189 sc_Register, /* 17: C_REGPARM register parameter */
1190 sc_Bits, /* 18; C_FIELD bitfield */
1272 sc_Text, /* 100: C_BLOCK block start/end */
1273 sc_Text, /* 101: C_FCN function start/end */
1274 sc_Info, /* 102: C_EOS end of struct/union/enum */
1275 sc_Nil, /* 103: C_FILE file start */
1276 sc_Nil, /* 104: C_LINE line number */
1277 sc_Nil, /* 105: C_ALIAS combined type info */
1278 sc_Nil, /* 106: C_HIDDEN ??? */
1281 /* Convert COFF storage class to ECOFF symbol type. */
1282 static const st_t map_coff_sym_type[] = {
1283 st_Nil, /* 0: C_NULL */
1284 st_Local, /* 1: C_AUTO auto var */
1285 st_Global, /* 2: C_EXT external */
1286 st_Static, /* 3: C_STAT static */
1287 st_Local, /* 4: C_REG register */
1288 st_Global, /* 5: C_EXTDEF ??? */
1289 st_Label, /* 6: C_LABEL label */
1290 st_Label, /* 7: C_ULABEL user label */
1291 st_Member, /* 8: C_MOS member of struct */
1292 st_Param, /* 9: C_ARG argument */
1293 st_Block, /* 10: C_STRTAG struct tag */
1294 st_Member, /* 11: C_MOU member of union */
1295 st_Block, /* 12: C_UNTAG union tag */
1296 st_Typedef, /* 13: C_TPDEF typedef */
1297 st_Static, /* 14: C_USTATIC ??? */
1298 st_Block, /* 15: C_ENTAG enum tag */
1299 st_Member, /* 16: C_MOE member of enum */
1300 st_Param, /* 17: C_REGPARM register parameter */
1301 st_Member, /* 18; C_FIELD bitfield */
1383 st_Block, /* 100: C_BLOCK block start/end */
1384 st_Proc, /* 101: C_FCN function start/end */
1385 st_End, /* 102: C_EOS end of struct/union/enum */
1386 st_File, /* 103: C_FILE file start */
1387 st_Nil, /* 104: C_LINE line number */
1388 st_Nil, /* 105: C_ALIAS combined type info */
1389 st_Nil, /* 106: C_HIDDEN ??? */
1393 /* Keep track of different sized allocation requests. */
1394 static alloc_info_t alloc_counts[ (int)alloc_type_last ];
1396 /* Various statics. */
1397 static efdr_t *cur_file_ptr = (efdr_t *) 0; /* current file desc. header */
1398 static proc_t *cur_proc_ptr = (proc_t *) 0; /* current procedure header */
1399 static thead_t *top_tag_head = (thead_t *) 0; /* top level tag head */
1400 static thead_t *cur_tag_head = (thead_t *) 0; /* current tag head */
1402 static int debug = 0; /* trace functions */
1404 static int stabs_seen = 0; /* != 0 if stabs have been seen */
1407 /* Pseudo symbol to use when putting stabs into the symbol table. */
1408 #ifndef STABS_SYMBOL
1409 #define STABS_SYMBOL "@stabs"
1412 static char stabs_symbol[] = STABS_SYMBOL;
1414 /* Prototypes for functions defined in this file. */
1416 static void add_varray_page PARAMS ((varray_t *vp));
1417 static symint_t add_string PARAMS ((varray_t *vp,
1418 struct hash_control *hash_tbl,
1420 shash_t **ret_hash));
1421 static localsym_t *add_ecoff_symbol PARAMS ((const char *str, st_t type,
1422 sc_t storage, symbolS *sym,
1425 static symint_t add_aux_sym_symint PARAMS ((symint_t aux_word));
1426 static symint_t add_aux_sym_rndx PARAMS ((int file_index,
1427 symint_t sym_index));
1428 static symint_t add_aux_sym_tir PARAMS ((type_info_t *t,
1430 thash_t **hash_tbl));
1431 static tag_t *get_tag PARAMS ((const char *tag, localsym_t *sym,
1433 static void add_unknown_tag PARAMS ((tag_t *ptag));
1434 static void add_procedure PARAMS ((char *func));
1435 static void add_file PARAMS ((const char *file_name, int indx));
1437 static char *sc_to_string PARAMS ((sc_t storage_class));
1438 static char *st_to_string PARAMS ((st_t symbol_type));
1440 static void obj_ecoff_def PARAMS ((int));
1441 static void obj_ecoff_dim PARAMS ((int));
1442 static void obj_ecoff_endef PARAMS ((int));
1443 static void obj_ecoff_file PARAMS ((int));
1444 static void obj_ecoff_scl PARAMS ((int));
1445 static void obj_ecoff_size PARAMS ((int));
1446 static void obj_ecoff_tag PARAMS ((int));
1447 static void obj_ecoff_type PARAMS ((int));
1448 static void obj_ecoff_val PARAMS ((int));
1449 static void obj_ecoff_stab PARAMS ((int));
1450 static void obj_ecoff_ent PARAMS ((int));
1451 static void obj_ecoff_begin PARAMS ((int));
1452 static void obj_ecoff_bend PARAMS ((int));
1453 static void obj_ecoff_end PARAMS ((int));
1454 static void obj_ecoff_fmask PARAMS ((int));
1455 static void obj_ecoff_frame PARAMS ((int));
1456 static void obj_ecoff_loc PARAMS ((int));
1457 static void obj_ecoff_mask PARAMS ((int));
1458 static void mark_stabs PARAMS ((int));
1459 static char *ecoff_add_bytes PARAMS ((char **buf, char **bufend,
1460 char *bufptr, long need));
1461 static long ecoff_longword_adjust PARAMS ((char **buf, char **bufend,
1462 long offset, char **bufptrptr));
1463 static long ecoff_build_lineno PARAMS ((char **buf, char **bufend,
1464 long offset, long *linecntptr));
1465 static long ecoff_build_symbols PARAMS ((char **buf, char **bufend,
1467 char **extbuf, char **extbufend,
1469 varray_t *ext_strings,
1470 struct hash_control *ext_str_hash));
1471 static long ecoff_build_procs PARAMS ((char **buf, char **bufend,
1473 static long ecoff_build_aux PARAMS ((char **buf, char **bufend,
1475 static long ecoff_build_strings PARAMS ((char **buf, char **bufend,
1478 static long ecoff_build_ss PARAMS ((char **buf, char **bufend,
1480 static long ecoff_build_fdr PARAMS ((char **buf, char **bufend,
1482 static void ecoff_set_vma PARAMS ((void));
1483 static page_t *allocate_cluster PARAMS ((unsigned long npages));
1484 static page_t *allocate_page PARAMS ((void));
1485 static scope_t *allocate_scope PARAMS ((void));
1486 static void free_scope PARAMS ((scope_t *ptr));
1487 static vlinks_t *allocate_vlinks PARAMS ((void));
1488 static shash_t *allocate_shash PARAMS ((void));
1489 static thash_t *allocate_thash PARAMS ((void));
1490 static tag_t *allocate_tag PARAMS ((void));
1491 static void free_tag PARAMS ((tag_t *ptr));
1492 static forward_t *allocate_forward PARAMS ((void));
1493 static thead_t *allocate_thead PARAMS ((void));
1494 static void free_thead PARAMS ((thead_t *ptr));
1495 static lineno_list_t *allocate_lineno_list PARAMS ((void));
1497 /* Why isn't this in some header file somewhere? In fact, is it even
1499 #define SKIP_WHITESPACES() \
1502 while (*input_line_pointer == ' ' \
1503 || *input_line_pointer == '\t') \
1504 ++input_line_pointer; \
1508 /* These are the pseudo-ops we support in this file. Only those
1509 relating to debugging information are supported here.
1511 The following pseudo-ops from the Kane and Heinrich MIPS book
1512 should be defined here, but are currently unsupported: .aent,
1513 .bgnb, .endb, .verstamp, .vreg.
1515 The following pseudo-ops from the Kane and Heinrich MIPS book are
1516 MIPS CPU specific, and should be defined by tc-mips.c: .alias,
1517 .extern, .galive, .gjaldef, .gjrlive, .livereg, .noalias, .option,
1518 .rdata, .sdata, .set.
1520 The following pseudo-ops from the Kane and Heinrich MIPS book are
1521 not MIPS CPU specific, but are also not ECOFF specific. I have
1522 only listed the ones which are not already in read.c. It's not
1523 completely clear where these should be defined, but tc-mips.c is
1524 probably the most reasonable place: .asciiz, .asm0, .endr, .err,
1525 .half, .lab, .repeat, .struct, .weakext. */
1527 const pseudo_typeS obj_pseudo_table[] =
1529 /* COFF style debugging information. .ln is not used; .loc is used
1531 { "def", obj_ecoff_def, 0 },
1532 { "dim", obj_ecoff_dim, 0 },
1533 { "endef", obj_ecoff_endef, 0 },
1534 { "file", obj_ecoff_file, 0 },
1535 { "scl", obj_ecoff_scl, 0 },
1536 { "size", obj_ecoff_size, 0 },
1537 { "tag", obj_ecoff_tag, 0 },
1538 { "type", obj_ecoff_type, 0 },
1539 { "val", obj_ecoff_val, 0 },
1541 /* stabs debugging information. */
1542 { "stabd", obj_ecoff_stab, 'd' },
1543 { "stabn", obj_ecoff_stab, 'n' },
1544 { "stabs", obj_ecoff_stab, 's' },
1546 /* ECOFF specific debugging information. */
1547 { "begin", obj_ecoff_begin, 0 },
1548 { "bend", obj_ecoff_bend, 0 },
1549 { "end", obj_ecoff_end, 0 },
1550 { "ent", obj_ecoff_ent, 0 },
1551 { "fmask", obj_ecoff_fmask, 0 },
1552 { "frame", obj_ecoff_frame, 0 },
1553 { "loc", obj_ecoff_loc, 0 },
1554 { "mask", obj_ecoff_mask, 0 },
1560 /* This function is called when the assembler starts up. */
1563 obj_read_begin_hook ()
1565 tag_hash = hash_new ();
1566 if (tag_hash == (struct hash_control *) NULL)
1567 as_fatal ("Can't create hash table");
1568 top_tag_head = allocate_thead ();
1569 top_tag_head->first_tag = (tag_t *) NULL;
1570 top_tag_head->free = (thead_t *) NULL;
1571 top_tag_head->prev = cur_tag_head;
1572 cur_tag_head = top_tag_head;
1575 /* This function is called when a symbol is created. */
1578 obj_symbol_new_hook (symbolP)
1581 symbolP->ecoff_file = cur_file_ptr;
1582 symbolP->ecoff_symbol = 0;
1583 symbolP->ecoff_undefined = 0;
1586 /* Add a page to a varray object. */
1589 add_varray_page (vp)
1590 varray_t *vp; /* varray to add page to */
1592 vlinks_t *new_links = allocate_vlinks ();
1595 if (vp->object_size > 1)
1596 new_links->datum = (page_t *) xcalloc (1, vp->object_size);
1599 new_links->datum = allocate_page ();
1601 alloc_counts[(int)alloc_type_varray].total_alloc++;
1602 alloc_counts[(int)alloc_type_varray].total_pages++;
1604 new_links->start_index = vp->num_allocated;
1605 vp->objects_last_page = 0;
1607 if (vp->first == (vlinks_t *) NULL) /* first allocation? */
1608 vp->first = vp->last = new_links;
1610 { /* 2nd or greater allocation */
1611 new_links->prev = vp->last;
1612 vp->last->next = new_links;
1613 vp->last = new_links;
1617 /* Add a string (and null pad) to one of the string tables. */
1620 add_string (vp, hash_tbl, str, ret_hash)
1621 varray_t *vp; /* string obstack */
1622 struct hash_control *hash_tbl; /* ptr to hash table */
1623 const char *str; /* string */
1624 shash_t **ret_hash; /* return hash pointer */
1626 register unsigned int len = strlen (str);
1627 register shash_t *hash_ptr;
1629 if (len >= PAGE_USIZE)
1630 as_fatal ("String too big (%lu bytes)", len);
1632 hash_ptr = (shash_t *) hash_find (hash_tbl, str);
1633 if (hash_ptr == (shash_t *) NULL)
1637 if (vp->objects_last_page + len >= PAGE_USIZE)
1640 ((vp->num_allocated + PAGE_USIZE - 1) / PAGE_USIZE) * PAGE_USIZE;
1641 add_varray_page (vp);
1644 hash_ptr = allocate_shash ();
1645 hash_ptr->indx = vp->num_allocated;
1647 hash_ptr->string = &vp->last->datum->byte[vp->objects_last_page];
1649 vp->objects_last_page += len + 1;
1650 vp->num_allocated += len + 1;
1652 strcpy (hash_ptr->string, str);
1654 err = hash_insert (hash_tbl, str, (char *) hash_ptr);
1656 as_fatal ("Inserting \"%s\" into string hash table: %s",
1660 if (ret_hash != (shash_t **) NULL)
1661 *ret_hash = hash_ptr;
1663 return hash_ptr->indx;
1666 /* Add debugging information for a symbol. */
1669 add_ecoff_symbol (str, type, storage, sym_value, value, indx)
1670 const char *str; /* symbol name */
1671 st_t type; /* symbol type */
1672 sc_t storage; /* storage class */
1673 symbolS *sym_value; /* associated symbol. */
1674 symint_t value; /* value of symbol */
1675 symint_t indx; /* index to local/aux. syms */
1678 register scope_t *pscope;
1679 register thead_t *ptag_head;
1680 register tag_t *ptag;
1681 register tag_t *ptag_next;
1682 register varray_t *vp = &cur_file_ptr->symbols;
1683 register int scope_delta = 0;
1684 shash_t *hash_ptr = (shash_t *) NULL;
1686 if (cur_file_ptr == (efdr_t *) NULL)
1687 as_fatal ("no current file pointer");
1689 vp = &cur_file_ptr->symbols;
1691 if (vp->objects_last_page == vp->objects_per_page)
1692 add_varray_page (vp);
1694 psym = &vp->last->datum->sym[ vp->objects_last_page++ ];
1696 if (str == (const char *) NULL && sym_value != (symbolS *) NULL)
1697 psym->name = S_GET_NAME (sym_value);
1700 psym->as_sym = sym_value;
1701 if (sym_value != (symbolS *) NULL)
1702 sym_value->ecoff_symbol = 1;
1703 psym->file_ptr = cur_file_ptr;
1704 psym->proc_ptr = cur_proc_ptr;
1705 psym->begin_ptr = (localsym_t *) NULL;
1706 psym->index_ptr = (aux_t *) NULL;
1707 psym->forward_ref = (forward_t *) NULL;
1708 psym->sym_index = -1;
1709 psym->ecoff_sym.value = value;
1710 psym->ecoff_sym.st = (unsigned) type;
1711 psym->ecoff_sym.sc = (unsigned) storage;
1712 psym->ecoff_sym.index = indx;
1714 /* If there is an associated symbol, we wait until the end of the
1715 assembly before deciding where to put the name (it may be just an
1716 external symbol). Otherwise, this is just a debugging symbol and
1717 the name should go with the current file. */
1718 if (sym_value == (symbolS *) NULL)
1719 psym->ecoff_sym.iss = ((str == (const char *) NULL)
1721 : add_string (&cur_file_ptr->strings,
1722 cur_file_ptr->str_hash,
1726 ++vp->num_allocated;
1728 if (MIPS_IS_STAB (&psym->ecoff_sym))
1731 /* Save the symbol within the hash table if this is a static
1732 item, and it has a name. */
1733 if (hash_ptr != (shash_t *) NULL
1734 && (type == st_Global || type == st_Static || type == st_Label
1735 || type == st_Proc || type == st_StaticProc))
1736 hash_ptr->sym_ptr = psym;
1738 /* push or pop a scope if appropriate. */
1744 case st_File: /* beginning of file */
1745 case st_Proc: /* procedure */
1746 case st_StaticProc: /* static procedure */
1747 case st_Block: /* begin scope */
1748 pscope = allocate_scope ();
1749 pscope->prev = cur_file_ptr->cur_scope;
1750 pscope->lsym = psym;
1751 pscope->type = type;
1752 cur_file_ptr->cur_scope = pscope;
1754 if (type != st_File)
1757 /* For every block type except file, struct, union, or
1758 enumeration blocks, push a level on the tag stack. We omit
1759 file types, so that tags can span file boundaries. */
1760 if (type != st_File && storage != sc_Info)
1762 ptag_head = allocate_thead ();
1763 ptag_head->first_tag = 0;
1764 ptag_head->prev = cur_tag_head;
1765 cur_tag_head = ptag_head;
1770 pscope = cur_file_ptr->cur_scope;
1771 if (pscope == (scope_t *) NULL)
1772 as_fatal ("too many st_End's");
1775 st_t begin_type = (st_t) pscope->lsym->ecoff_sym.st;
1777 psym->begin_ptr = pscope->lsym;
1779 if (begin_type != st_File)
1782 /* Except for file, structure, union, or enumeration end
1783 blocks remove all tags created within this scope. */
1784 if (begin_type != st_File && storage != sc_Info)
1786 ptag_head = cur_tag_head;
1787 cur_tag_head = ptag_head->prev;
1789 for (ptag = ptag_head->first_tag;
1790 ptag != (tag_t *) NULL;
1793 if (ptag->forward_ref != (forward_t *) NULL)
1794 add_unknown_tag (ptag);
1796 ptag_next = ptag->same_block;
1797 ptag->hash_ptr->tag_ptr = ptag->same_name;
1801 free_thead (ptag_head);
1804 cur_file_ptr->cur_scope = pscope->prev;
1806 /* block begin gets next sym #. This is set when we know
1807 the symbol index value. */
1809 /* Functions push two or more aux words as follows:
1810 1st word: index+1 of the end symbol (filled in later).
1811 2nd word: type of the function (plus any aux words needed).
1812 Also, tie the external pointer back to the function begin symbol. */
1813 if (begin_type != st_File && begin_type != st_Block)
1816 varray_t *vp = &cur_file_ptr->aux_syms;
1818 pscope->lsym->ecoff_sym.index = add_aux_sym_symint (0);
1819 pscope->lsym->index_ptr =
1820 &vp->last->datum->aux[vp->objects_last_page - 1];
1821 type = add_aux_sym_tir (&last_func_type_info,
1823 &cur_file_ptr->thash_head[0]);
1825 if (last_func_sym_value != (symbolS *) NULL)
1827 last_func_sym_value->ifd = cur_file_ptr->file_index;
1828 last_func_sym_value->index = type;
1833 free_scope (pscope);
1837 cur_file_ptr->nested_scopes += scope_delta;
1840 if (debug && type != st_File
1841 && (debug > 2 || type == st_Block || type == st_End
1842 || type == st_Proc || type == st_StaticProc))
1844 char *sc_str = sc_to_string (storage);
1845 char *st_str = st_to_string (type);
1846 int depth = cur_file_ptr->nested_scopes + (scope_delta < 0);
1849 "\tlsym\tv= %10ld, depth= %2d, sc= %-12s",
1850 value, depth, sc_str);
1852 if (str_start && str_end_p1 - str_start > 0)
1853 fprintf (stderr, " st= %-11s name= %.*s\n", st_str, str_end_p1 - str_start, str_start);
1856 unsigned long len = strlen (st_str);
1857 fprintf (stderr, " st= %.*s\n", len-1, st_str);
1865 /* Add an auxiliary symbol (passing a symint). This is actually used
1866 for integral aux types, not just symints. */
1869 add_aux_sym_symint (aux_word)
1870 symint_t aux_word; /* auxiliary information word */
1872 register varray_t *vp;
1873 register aux_t *aux_ptr;
1875 if (cur_file_ptr == (efdr_t *) NULL)
1876 as_fatal ("no current file pointer");
1878 vp = &cur_file_ptr->aux_syms;
1880 if (vp->objects_last_page == vp->objects_per_page)
1881 add_varray_page (vp);
1883 aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
1884 aux_ptr->type = aux_isym;
1885 aux_ptr->data.isym = aux_word;
1887 return vp->num_allocated++;
1891 /* Add an auxiliary symbol (passing a file/symbol index combo). */
1894 add_aux_sym_rndx (file_index, sym_index)
1898 register varray_t *vp;
1899 register aux_t *aux_ptr;
1901 if (cur_file_ptr == (efdr_t *) NULL)
1902 as_fatal ("no current file pointer");
1904 vp = &cur_file_ptr->aux_syms;
1906 if (vp->objects_last_page == vp->objects_per_page)
1907 add_varray_page (vp);
1909 aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
1910 aux_ptr->type = aux_rndx;
1911 aux_ptr->data.rndx.rfd = file_index;
1912 aux_ptr->data.rndx.index = sym_index;
1914 return vp->num_allocated++;
1917 /* Add an auxiliary symbol (passing the basic type and possibly
1918 type qualifiers). */
1921 add_aux_sym_tir (t, state, hash_tbl)
1922 type_info_t *t; /* current type information */
1923 hash_state_t state; /* whether to hash type or not */
1924 thash_t **hash_tbl; /* pointer to hash table to use */
1926 register varray_t *vp;
1927 register aux_t *aux_ptr;
1928 static AUXU init_aux;
1933 if (cur_file_ptr == (efdr_t *) NULL)
1934 as_fatal ("no current file pointer");
1936 vp = &cur_file_ptr->aux_syms;
1939 aux.ti.bt = (int) t->basic_type;
1940 aux.ti.continued = 0;
1941 aux.ti.fBitfield = t->bitfield;
1943 aux.ti.tq0 = (int) t->type_qualifiers[0];
1944 aux.ti.tq1 = (int) t->type_qualifiers[1];
1945 aux.ti.tq2 = (int) t->type_qualifiers[2];
1946 aux.ti.tq3 = (int) t->type_qualifiers[3];
1947 aux.ti.tq4 = (int) t->type_qualifiers[4];
1948 aux.ti.tq5 = (int) t->type_qualifiers[5];
1951 /* For anything that adds additional information, we must not hash,
1952 so check here, and reset our state. */
1954 if (state != hash_no
1955 && (t->type_qualifiers[0] == tq_Array
1956 || t->type_qualifiers[1] == tq_Array
1957 || t->type_qualifiers[2] == tq_Array
1958 || t->type_qualifiers[3] == tq_Array
1959 || t->type_qualifiers[4] == tq_Array
1960 || t->type_qualifiers[5] == tq_Array
1961 || t->basic_type == bt_Struct
1962 || t->basic_type == bt_Union
1963 || t->basic_type == bt_Enum
1965 || t->num_dims > 0))
1968 /* See if we can hash this type, and save some space, but some types
1969 can't be hashed (because they contain arrays or continuations),
1970 and others can be put into the hash list, but cannot use existing
1971 types because other aux entries precede this one. */
1973 if (state != hash_no)
1975 register thash_t *hash_ptr;
1976 register symint_t hi;
1978 hi = aux.isym & ((1 << HASHBITS) - 1);
1981 for (hash_ptr = hash_tbl[hi];
1982 hash_ptr != (thash_t *)0;
1983 hash_ptr = hash_ptr->next)
1985 if (aux.isym == hash_ptr->type.isym)
1989 if (hash_ptr != (thash_t *) NULL && state == hash_yes)
1990 return hash_ptr->indx;
1992 if (hash_ptr == (thash_t *) NULL)
1994 hash_ptr = allocate_thash ();
1995 hash_ptr->next = hash_tbl[hi];
1996 hash_ptr->type = aux;
1997 hash_ptr->indx = vp->num_allocated;
1998 hash_tbl[hi] = hash_ptr;
2002 /* Everything is set up, add the aux symbol. */
2003 if (vp->objects_last_page == vp->objects_per_page)
2004 add_varray_page (vp);
2006 aux_ptr = &vp->last->datum->aux[ vp->objects_last_page++ ];
2007 aux_ptr->type = aux_tir;
2008 aux_ptr->data = aux;
2010 ret = vp->num_allocated++;
2012 /* Add bitfield length if it exists.
2014 NOTE: Mips documentation claims bitfield goes at the end of the
2015 AUX record, but the DECstation compiler emits it here.
2016 (This would only make a difference for enum bitfields.)
2018 Also note: We use the last size given since gcc may emit 2
2019 for an enum bitfield. */
2022 (void) add_aux_sym_symint ((symint_t)t->sizes[t->num_sizes-1]);
2025 /* Add tag information if needed. Structure, union, and enum
2026 references add 2 aux symbols: a [file index, symbol index]
2027 pointer to the structure type, and the current file index. */
2029 if (t->basic_type == bt_Struct
2030 || t->basic_type == bt_Union
2031 || t->basic_type == bt_Enum)
2033 register symint_t file_index = t->tag_ptr->ifd;
2034 register localsym_t *sym = t->tag_ptr->sym;
2035 register forward_t *forward_ref = allocate_forward ();
2037 if (sym != (localsym_t *) NULL)
2039 forward_ref->next = sym->forward_ref;
2040 sym->forward_ref = forward_ref;
2044 forward_ref->next = t->tag_ptr->forward_ref;
2045 t->tag_ptr->forward_ref = forward_ref;
2048 (void) add_aux_sym_rndx (ST_RFDESCAPE, indexNil);
2049 forward_ref->index_ptr
2050 = &vp->last->datum->aux[ vp->objects_last_page - 1];
2052 (void) add_aux_sym_symint (file_index);
2053 forward_ref->ifd_ptr
2054 = &vp->last->datum->aux[ vp->objects_last_page - 1];
2057 /* Add information about array bounds if they exist. */
2058 for (i = 0; i < t->num_dims; i++)
2060 (void) add_aux_sym_rndx (ST_RFDESCAPE,
2061 cur_file_ptr->int_type);
2063 (void) add_aux_sym_symint (cur_file_ptr->file_index); /* file index*/
2064 (void) add_aux_sym_symint ((symint_t) 0); /* low bound */
2065 (void) add_aux_sym_symint (t->dimensions[i] - 1); /* high bound*/
2066 (void) add_aux_sym_symint ((t->dimensions[i] == 0) /* stride */
2068 : (t->sizes[i] * 8) / t->dimensions[i]);
2071 /* NOTE: Mips documentation claims that the bitfield width goes here.
2072 But it needs to be emitted earlier. */
2077 /* Add a tag to the tag table (unless it already exists). */
2080 get_tag (tag, sym, basic_type)
2081 const char *tag; /* tag name */
2082 localsym_t *sym; /* tag start block */
2083 bt_t basic_type; /* bt_Struct, bt_Union, or bt_Enum */
2089 if (cur_file_ptr == (efdr_t *) NULL)
2090 as_fatal ("no current file pointer");
2092 hash_ptr = (shash_t *) hash_find (tag_hash, tag);
2094 if (hash_ptr != (shash_t *) NULL
2095 && hash_ptr->tag_ptr != (tag_t *) NULL)
2097 tag_ptr = hash_ptr->tag_ptr;
2098 if (sym != (localsym_t *) NULL)
2100 tag_ptr->basic_type = basic_type;
2101 tag_ptr->ifd = cur_file_ptr->file_index;
2107 if (hash_ptr == (shash_t *) NULL)
2109 hash_ptr = allocate_shash ();
2110 err = hash_insert (tag_hash, tag, (char *) hash_ptr);
2112 as_fatal ("Inserting \"%s\" into tag hash table: %s",
2116 tag_ptr = allocate_tag ();
2117 tag_ptr->forward_ref = (forward_t *) NULL;
2118 tag_ptr->hash_ptr = hash_ptr;
2119 tag_ptr->same_name = hash_ptr->tag_ptr;
2120 tag_ptr->basic_type = basic_type;
2122 tag_ptr->ifd = ((sym == (localsym_t *) NULL)
2124 : cur_file_ptr->file_index);
2125 tag_ptr->same_block = cur_tag_head->first_tag;
2127 cur_tag_head->first_tag = tag_ptr;
2128 hash_ptr->tag_ptr = tag_ptr;
2133 /* Add an unknown {struct, union, enum} tag. */
2136 add_unknown_tag (ptag)
2137 tag_t *ptag; /* pointer to tag information */
2139 shash_t *hash_ptr = ptag->hash_ptr;
2140 char *name = hash_ptr->string;
2147 char *agg_type = "{unknown aggregate type}";
2148 switch (ptag->basic_type)
2150 case bt_Struct: agg_type = "struct"; break;
2151 case bt_Union: agg_type = "union"; break;
2152 case bt_Enum: agg_type = "enum"; break;
2156 fprintf (stderr, "unknown %s %.*s found\n", agg_type,
2157 hash_ptr->len, name_start);
2161 sym = add_ecoff_symbol (name,
2168 (void) add_ecoff_symbol (name,
2175 for (pf = &sym->forward_ref; *pf != (forward_t *) NULL; pf = &(*pf)->next)
2177 *pf = ptag->forward_ref;
2180 /* Add a procedure to the current file's list of procedures, and record
2181 this is the current procedure. */
2184 add_procedure (func)
2185 char *func; /* func name */
2187 register varray_t *vp;
2188 register proc_t *new_proc_ptr;
2192 fputc ('\n', stderr);
2195 if (cur_file_ptr == (efdr_t *) NULL)
2196 as_fatal ("no current file pointer");
2198 vp = &cur_file_ptr->procs;
2200 if (vp->objects_last_page == vp->objects_per_page)
2201 add_varray_page (vp);
2203 cur_proc_ptr = new_proc_ptr = &vp->last->datum->proc[vp->objects_last_page++];
2205 vp->num_allocated++;
2207 new_proc_ptr->pdr.isym = -1;
2208 new_proc_ptr->pdr.iline = -1;
2209 new_proc_ptr->pdr.lnLow = -1;
2210 new_proc_ptr->pdr.lnHigh = -1;
2212 /* Push the start of the function. */
2213 new_proc_ptr->sym = add_ecoff_symbol ((const char *) NULL, st_Proc, sc_Text,
2214 symbol_find_or_make (func),
2215 (symint_t) 0, (symint_t) 0);
2219 /* Fill in the linenos preceding the .ent, if any. */
2220 if (noproc_lineno != (lineno_list_t *) NULL)
2224 for (l = noproc_lineno; l != (lineno_list_t *) NULL; l = l->next)
2225 l->proc = new_proc_ptr;
2226 *last_lineno_ptr = noproc_lineno;
2227 while (*last_lineno_ptr != NULL)
2228 last_lineno_ptr = &(*last_lineno_ptr)->next;
2229 noproc_lineno = (lineno_list_t *) NULL;
2233 /* Add a new filename, and set up all of the file relative
2234 virtual arrays (strings, symbols, aux syms, etc.). Record
2235 where the current file structure lives. */
2238 add_file (file_name, indx)
2239 const char *file_name; /* file name */
2242 register int first_ch;
2243 register efdr_t *fil_ptr;
2247 fprintf (stderr, "\tfile\t%.*s\n", len, file_start);
2250 /* If the file name is NULL, then no .file symbol appeared, and we
2251 want to use the actual file name. Unfortunately, we don't have a
2252 clean way to access it. */
2253 if (file_name == (const char *) NULL)
2255 extern char *logical_input_file;
2256 extern char *physical_input_file;
2258 if (first_file != (efdr_t *) NULL)
2259 as_fatal ("fake .file after real one");
2260 file_name = logical_input_file;
2261 if (file_name == (const char *) NULL)
2263 file_name = physical_input_file;
2264 if (file_name == (const char *) NULL)
2265 file_name = "UNKNOWN";
2269 /* If we're creating stabs, then we don't actually make a new FDR.
2270 Instead, we just create a stabs symbol. */
2273 (void) add_ecoff_symbol (file_name, st_Nil, sc_Nil,
2274 symbol_new ("L0\001", now_seg,
2275 frag_now_fix (), frag_now),
2276 0, MIPS_MARK_STAB (N_SOL));
2280 first_ch = *file_name;
2282 /* See if the file has already been created. */
2283 for (fil_ptr = first_file;
2284 fil_ptr != (efdr_t *) NULL;
2285 fil_ptr = fil_ptr->next_file)
2287 if (first_ch == fil_ptr->name[0]
2288 && strcmp (file_name, fil_ptr->name) == 0)
2290 cur_file_ptr = fil_ptr;
2295 /* If this is a new file, create it. */
2296 if (fil_ptr == (efdr_t *) NULL)
2298 if (file_desc.objects_last_page == file_desc.objects_per_page)
2299 add_varray_page (&file_desc);
2301 fil_ptr = cur_file_ptr =
2302 &file_desc.last->datum->file[file_desc.objects_last_page++];
2303 *fil_ptr = init_file;
2305 fil_ptr->file_index = indx;
2306 ++file_desc.num_allocated;
2308 /* Allocate the string hash table. */
2309 fil_ptr->str_hash = hash_new ();
2310 if (fil_ptr->str_hash == (struct hash_control *) NULL)
2311 as_fatal ("Can't create hash table");
2313 /* Make sure 0 byte in string table is null */
2314 add_string (&fil_ptr->strings,
2319 if (strlen (file_name) > PAGE_USIZE - 2)
2320 as_fatal ("Filename goes over one page boundary.");
2322 /* Push the start of the filename. We assume that the filename
2323 will be stored at string offset 1. */
2324 (void) add_ecoff_symbol (file_name, st_File, sc_Text,
2326 (symint_t) 0, (symint_t) 0);
2327 fil_ptr->fdr.rss = 1;
2328 fil_ptr->name = &fil_ptr->strings.last->datum->byte[1];
2330 /* Update the linked list of file descriptors. */
2331 *last_file_ptr = fil_ptr;
2332 last_file_ptr = &fil_ptr->next_file;
2334 /* Add void & int types to the file (void should be first to catch
2335 errant 0's within the index fields). */
2336 fil_ptr->void_type = add_aux_sym_tir (&void_type_info,
2338 &cur_file_ptr->thash_head[0]);
2340 fil_ptr->int_type = add_aux_sym_tir (&int_type_info,
2342 &cur_file_ptr->thash_head[0]);
2348 /* Convert storage class to string. */
2351 sc_to_string(storage_class)
2354 switch(storage_class)
2356 case sc_Nil: return "Nil,";
2357 case sc_Text: return "Text,";
2358 case sc_Data: return "Data,";
2359 case sc_Bss: return "Bss,";
2360 case sc_Register: return "Register,";
2361 case sc_Abs: return "Abs,";
2362 case sc_Undefined: return "Undefined,";
2363 case sc_CdbLocal: return "CdbLocal,";
2364 case sc_Bits: return "Bits,";
2365 case sc_CdbSystem: return "CdbSystem,";
2366 case sc_RegImage: return "RegImage,";
2367 case sc_Info: return "Info,";
2368 case sc_UserStruct: return "UserStruct,";
2369 case sc_SData: return "SData,";
2370 case sc_SBss: return "SBss,";
2371 case sc_RData: return "RData,";
2372 case sc_Var: return "Var,";
2373 case sc_Common: return "Common,";
2374 case sc_SCommon: return "SCommon,";
2375 case sc_VarRegister: return "VarRegister,";
2376 case sc_Variant: return "Variant,";
2377 case sc_SUndefined: return "SUndefined,";
2378 case sc_Init: return "Init,";
2379 case sc_Max: return "Max,";
2389 /* Convert symbol type to string. */
2392 st_to_string(symbol_type)
2397 case st_Nil: return "Nil,";
2398 case st_Global: return "Global,";
2399 case st_Static: return "Static,";
2400 case st_Param: return "Param,";
2401 case st_Local: return "Local,";
2402 case st_Label: return "Label,";
2403 case st_Proc: return "Proc,";
2404 case st_Block: return "Block,";
2405 case st_End: return "End,";
2406 case st_Member: return "Member,";
2407 case st_Typedef: return "Typedef,";
2408 case st_File: return "File,";
2409 case st_RegReloc: return "RegReloc,";
2410 case st_Forward: return "Forward,";
2411 case st_StaticProc: return "StaticProc,";
2412 case st_Constant: return "Constant,";
2413 case st_Str: return "String,";
2414 case st_Number: return "Number,";
2415 case st_Expr: return "Expr,";
2416 case st_Type: return "Type,";
2417 case st_Max: return "Max,";
2425 /* Parse .begin directives which have a label as the first argument
2426 which gives the location of the start of the block. */
2429 obj_ecoff_begin (ignore)
2435 if (cur_file_ptr == (efdr_t *) NULL)
2437 as_warn (".begin directive without a preceding .file directive");
2438 demand_empty_rest_of_line ();
2442 if (cur_proc_ptr == (proc_t *) NULL)
2444 as_warn (".begin directive without a preceding .ent directive");
2445 demand_empty_rest_of_line ();
2449 name = input_line_pointer;
2450 name_end = get_symbol_end ();
2452 (void) add_ecoff_symbol ((const char *) NULL, st_Block, sc_Text,
2453 symbol_find_or_make (name),
2454 (symint_t) 0, (symint_t) 0);
2456 *input_line_pointer = name_end;
2458 /* The line number follows, but we don't use it. */
2459 (void) get_absolute_expression ();
2460 demand_empty_rest_of_line ();
2463 /* Parse .bend directives which have a label as the first argument
2464 which gives the location of the end of the block. */
2467 obj_ecoff_bend (ignore)
2474 if (cur_file_ptr == (efdr_t *) NULL)
2476 as_warn (".bend directive without a preceding .file directive");
2477 demand_empty_rest_of_line ();
2481 if (cur_proc_ptr == (proc_t *) NULL)
2483 as_warn (".bend directive without a preceding .ent directive");
2484 demand_empty_rest_of_line ();
2488 name = input_line_pointer;
2489 name_end = get_symbol_end ();
2491 /* The value is the distance between the .bend directive and the
2492 corresponding symbol. We fill in the offset when we write out
2494 endsym = symbol_find (name);
2495 if (endsym == (symbolS *) NULL)
2496 as_warn (".bend directive names unknown symbol");
2498 (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text, endsym,
2499 (symint_t) 0, (symint_t) 0);
2501 *input_line_pointer = name_end;
2503 /* The line number follows, but we don't use it. */
2504 (void) get_absolute_expression ();
2505 demand_empty_rest_of_line ();
2508 /* COFF debugging information is provided as a series of directives
2509 (.def, .scl, etc.). We build up information as we read the
2510 directives in the following static variables, and file it away when
2511 we reach the .endef directive. */
2512 static char *coff_sym_name;
2513 static type_info_t coff_type;
2514 static sc_t coff_storage_class;
2515 static st_t coff_symbol_type;
2516 static int coff_is_function;
2517 static char *coff_tag;
2518 static long coff_value; /* FIXME: Might be 64 bits. */
2519 symbolS *coff_sym_value;
2520 static int coff_inside_enumeration;
2522 /* Handle a .def directive: start defining a symbol. */
2525 obj_ecoff_def (ignore)
2531 SKIP_WHITESPACES ();
2533 name = input_line_pointer;
2534 name_end = get_symbol_end ();
2536 if (coff_sym_name != (char *) NULL)
2537 as_warn (".def pseudo-op used inside of .def/.endef; ignored");
2538 else if (*name == '\0')
2539 as_warn ("Empty symbol name in .def; ignored");
2542 if (coff_sym_name != (char *) NULL)
2543 free (coff_sym_name);
2544 if (coff_tag != (char *) NULL)
2546 coff_sym_name = (char *) xmalloc (strlen (name) + 1);
2547 strcpy (coff_sym_name, name);
2548 coff_type = type_info_init;
2549 coff_storage_class = sc_Nil;
2550 coff_symbol_type = st_Nil;
2551 coff_is_function = 0;
2552 coff_tag = (char *) NULL;
2554 coff_sym_value = (symbolS *) NULL;
2557 *input_line_pointer = name_end;
2559 demand_empty_rest_of_line ();
2562 /* Handle a .dim directive, used to give dimensions for an array. The
2563 arguments are comma separated numbers. mips-tfile assumes that
2564 there will not be more than 6 dimensions, and gdb won't read any
2565 more than that anyhow, so I will also make that assumption. */
2568 obj_ecoff_dim (ignore)
2574 if (coff_sym_name == (char *) NULL)
2576 as_warn (".dim pseudo-op used outside of .def/.endef; ignored");
2577 demand_empty_rest_of_line ();
2581 for (i = 0; i < N_TQ; i++)
2583 SKIP_WHITESPACES ();
2584 dimens[i] = get_absolute_expression ();
2585 if (*input_line_pointer == ',')
2586 ++input_line_pointer;
2589 if (*input_line_pointer != '\n'
2590 && *input_line_pointer != ';')
2591 as_warn ("Badly formed .dim directive");
2599 /* The dimensions are stored away in reverse order. */
2602 if (coff_type.num_dims >= N_TQ)
2604 as_warn ("Too many .dim entries");
2607 coff_type.dimensions[coff_type.num_dims] = dimens[i];
2608 ++coff_type.num_dims;
2611 demand_empty_rest_of_line ();
2614 /* Handle a .scl directive, which sets the COFF storage class of the
2618 obj_ecoff_scl (ignore)
2623 if (coff_sym_name == (char *) NULL)
2625 as_warn (".scl pseudo-op used outside of .def/.endef; ignored");
2626 demand_empty_rest_of_line ();
2630 val = get_absolute_expression ();
2632 coff_symbol_type = map_coff_sym_type[val];
2633 coff_storage_class = map_coff_storage[val];
2635 demand_empty_rest_of_line ();
2638 /* Handle a .size directive. For some reason mips-tfile.c thinks that
2639 .size can have multiple arguments. We humor it, although gcc will
2640 never generate more than one argument. */
2643 obj_ecoff_size (ignore)
2649 if (coff_sym_name == (char *) NULL)
2651 as_warn (".size pseudo-op used outside of .def/.endef; ignored");
2652 demand_empty_rest_of_line ();
2656 for (i = 0; i < N_TQ; i++)
2658 SKIP_WHITESPACES ();
2659 sizes[i] = get_absolute_expression ();
2660 if (*input_line_pointer == ',')
2661 ++input_line_pointer;
2664 if (*input_line_pointer != '\n'
2665 && *input_line_pointer != ';')
2666 as_warn ("Badly formed .size directive");
2674 /* The sizes are stored away in reverse order. */
2677 if (coff_type.num_sizes >= N_TQ)
2679 as_warn ("Too many .size entries");
2682 coff_type.sizes[coff_type.num_sizes] = sizes[i];
2683 ++coff_type.num_sizes;
2686 demand_empty_rest_of_line ();
2689 /* Handle the .type directive, which gives the COFF type of the
2693 obj_ecoff_type (ignore)
2700 if (coff_sym_name == (char *) NULL)
2702 as_warn (".type pseudo-op used outside of .def/.endef; ignored");
2703 demand_empty_rest_of_line ();
2707 val = get_absolute_expression ();
2709 coff_type.orig_type = BTYPE (val);
2710 coff_type.basic_type = map_coff_types[coff_type.orig_type];
2712 tq_ptr = &coff_type.type_qualifiers[N_TQ];
2713 while (val &~ N_BTMASK)
2715 if (tq_ptr == &coff_type.type_qualifiers[0])
2717 as_warn ("Too derived values in .type argument");
2722 else if (ISFCN (val))
2723 *--tq_ptr = tq_Proc;
2724 else if (ISARY (val))
2725 *--tq_ptr = tq_Array;
2727 as_fatal ("Unrecognized .type argument");
2732 tq_shft = &coff_type.type_qualifiers[0];
2733 while (tq_ptr != &coff_type.type_qualifiers[N_TQ])
2734 *tq_shft++ = *tq_ptr++;
2736 if (tq_shft != &coff_type.type_qualifiers[0] && tq_shft[-1] == tq_Proc)
2738 /* If this is a function, ignore it, so that we don't get two
2739 entries (one from the .ent, and one for the .def that
2740 precedes it). Save the type information so that the end
2741 block can properly add it after the begin block index. For
2742 MIPS knows what reason, we must strip off the function type
2744 coff_is_function = 1;
2745 tq_shft[-1] = tq_Nil;
2748 while (tq_shft != &coff_type.type_qualifiers[N_TQ])
2749 *tq_shft++ = tq_Nil;
2751 demand_empty_rest_of_line ();
2754 /* Handle the .tag directive, which gives the name of a structure,
2758 obj_ecoff_tag (ignore)
2764 if (coff_sym_name == (char *) NULL)
2766 as_warn (".tag pseudo-op used outside of .def/.endef; ignored");
2767 demand_empty_rest_of_line ();
2771 name = input_line_pointer;
2772 name_end = get_symbol_end ();
2774 coff_tag = (char *) xmalloc (strlen (name) + 1);
2775 strcpy (coff_tag, name);
2777 *input_line_pointer = name_end;
2779 demand_empty_rest_of_line ();
2782 /* Handle the .val directive, which gives the value of the symbol. It
2783 may be the name of a static or global symbol. */
2786 obj_ecoff_val (ignore)
2789 if (coff_sym_name == (char *) NULL)
2791 as_warn (".val pseudo-op used outside of .def/.endef; ignored");
2792 demand_empty_rest_of_line ();
2796 if (! is_name_beginner ((unsigned char) *input_line_pointer))
2797 coff_value = get_absolute_expression ();
2803 name = input_line_pointer;
2804 name_end = get_symbol_end ();
2806 if (strcmp (name, ".") == 0)
2807 as_warn ("`.val .' not supported");
2809 coff_sym_value = symbol_find_or_make (name);
2811 *input_line_pointer = name_end;
2813 /* FIXME: gcc can generate address expressions here in unusual
2814 cases (search for "obscure" in sdbout.c), although this is
2815 very unlikely for a MIPS chip. */
2818 demand_empty_rest_of_line ();
2821 /* Handle the .endef directive, which terminates processing of COFF
2822 debugging information for a symbol. */
2825 obj_ecoff_endef (ignore)
2832 demand_empty_rest_of_line ();
2834 if (coff_sym_name == (char *) NULL)
2836 as_warn (".endef pseudo-op used before .def; ignored");
2840 name = coff_sym_name;
2841 coff_sym_name = (char *) NULL;
2843 /* If the symbol is a static or external, we have already gotten the
2844 appropriate type and class, so make sure we don't override those
2845 values. This is needed because there are some type and classes
2846 that are not in COFF, such as short data, etc. */
2847 if (coff_sym_value != (symbolS *) NULL)
2849 coff_symbol_type = st_Nil;
2850 coff_storage_class = sc_Nil;
2853 coff_type.extra_sizes = coff_tag != (char *) NULL;
2854 if (coff_type.num_dims > 0)
2856 int diff = coff_type.num_dims - coff_type.num_sizes;
2857 int i = coff_type.num_dims - 1;
2860 if (coff_type.num_sizes != 1 || diff < 0)
2862 as_warn ("Bad COFF debugging info");
2866 /* If this is an array, make sure the same number of dimensions
2867 and sizes were passed, creating extra sizes for multiply
2868 dimensioned arrays if not passed. */
2869 coff_type.extra_sizes = 0;
2872 j = (sizeof (coff_type.sizes) / sizeof (coff_type.sizes[0])) - 1;
2875 coff_type.sizes[j] = (((j - diff) >= 0)
2876 ? coff_type.sizes[j - diff]
2881 coff_type.num_sizes = i + 1;
2882 for (i--; i >= 0; i--)
2883 coff_type.sizes[i] = (coff_type.sizes[i + 1]
2884 / coff_type.dimensions[i + 1]);
2887 else if (coff_symbol_type == st_Member
2888 && coff_type.num_sizes - coff_type.extra_sizes == 1)
2890 /* Is this a bitfield? This is indicated by a structure memeber
2891 having a size field that isn't an array. */
2892 coff_type.bitfield = 1;
2895 /* Except for enumeration members & begin/ending of scopes, put the
2896 type word in the aux. symbol table. */
2897 if (coff_symbol_type == st_Block || coff_symbol_type == st_End)
2899 else if (coff_inside_enumeration)
2900 indx = cur_file_ptr->void_type;
2903 if (coff_type.basic_type == bt_Struct
2904 || coff_type.basic_type == bt_Union
2905 || coff_type.basic_type == bt_Enum)
2907 if (coff_tag == (char *) NULL)
2909 as_warn ("No tag specified for %s", name);
2913 coff_type.tag_ptr = get_tag (coff_tag, (localsym_t *) NULL,
2914 coff_type.basic_type);
2917 if (coff_is_function)
2919 last_func_type_info = coff_type;
2920 last_func_sym_value = coff_sym_value;
2924 indx = add_aux_sym_tir (&coff_type,
2926 &cur_file_ptr->thash_head[0]);
2929 /* Do any last minute adjustments that are necessary. */
2930 switch (coff_symbol_type)
2935 /* For the beginning of structs, unions, and enumerations, the
2936 size info needs to be passed in the value field. */
2938 if (coff_type.num_sizes - coff_type.num_dims - coff_type.extra_sizes
2941 as_warn ("Bad COFF debugging information");
2945 coff_value = coff_type.sizes[0];
2947 coff_inside_enumeration = (coff_type.orig_type == T_ENUM);
2950 /* For the end of structs, unions, and enumerations, omit the
2951 name which is always ".eos". This needs to be done last, so
2952 that any error reporting above gives the correct name. */
2955 name = (char *) NULL;
2957 coff_inside_enumeration = 0;
2960 /* Members of structures and unions that aren't bitfields, need
2961 to adjust the value from a byte offset to a bit offset.
2962 Members of enumerations do not have the value adjusted, and
2963 can be distinguished by indx == indexNil. For enumerations,
2964 update the maximum enumeration value. */
2966 if (! coff_type.bitfield && ! coff_inside_enumeration)
2972 /* Add the symbol. */
2973 sym = add_ecoff_symbol (name,
2980 /* deal with struct, union, and enum tags. */
2981 if (coff_symbol_type == st_Block)
2983 /* Create or update the tag information. */
2984 tag_t *tag_ptr = get_tag (name,
2986 coff_type.basic_type);
2989 /* Remember any forward references. */
2990 for (pf = &sym->forward_ref;
2991 *pf != (forward_t *) NULL;
2994 *pf = tag_ptr->forward_ref;
2995 tag_ptr->forward_ref = (forward_t *) NULL;
2999 /* Parse .end directives. */
3002 obj_ecoff_end (ignore)
3010 if (cur_file_ptr == (efdr_t *) NULL)
3012 as_warn (".end directive without a preceding .file directive");
3013 demand_empty_rest_of_line ();
3017 if (cur_proc_ptr == (proc_t *) NULL)
3019 as_warn (".end directive without a preceding .ent directive");
3020 demand_empty_rest_of_line ();
3024 name = input_line_pointer;
3025 name_end = get_symbol_end ();
3028 if (! is_name_beginner (ch))
3030 as_warn (".end directive has no name");
3031 *input_line_pointer = name_end;
3032 demand_empty_rest_of_line ();
3036 /* The value is the distance between the .end directive and the
3037 corresponding symbol. We create a fake symbol to hold the
3038 current location, and put in the offset when we write out the
3040 ent = symbol_find (name);
3041 if (ent == (symbolS *) NULL)
3042 as_warn (".end directive names unknown symbol");
3044 (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text,
3045 symbol_new ("L0\001", now_seg,
3046 frag_now_fix (), frag_now),
3047 (symint_t) 0, (symint_t) 0);
3049 cur_proc_ptr = (proc_t *) NULL;
3051 *input_line_pointer = name_end;
3052 demand_empty_rest_of_line ();
3055 /* Parse .ent directives. */
3058 obj_ecoff_ent (ignore)
3065 if (cur_file_ptr == (efdr_t *) NULL)
3066 add_file ((const char *) NULL, 0);
3068 if (cur_proc_ptr != (proc_t *) NULL)
3070 as_warn ("second .ent directive found before .end directive");
3071 demand_empty_rest_of_line ();
3075 name = input_line_pointer;
3076 name_end = get_symbol_end ();
3079 if (! is_name_beginner (ch))
3081 as_warn (".ent directive has no name");
3082 *input_line_pointer = name_end;
3083 demand_empty_rest_of_line ();
3087 add_procedure (name);
3089 *input_line_pointer = name_end;
3090 demand_empty_rest_of_line ();
3093 /* Parse .file directives. */
3096 obj_ecoff_file (ignore)
3103 if (cur_proc_ptr != (proc_t *) NULL)
3105 as_warn ("No way to handle .file within .ent/.end section");
3106 demand_empty_rest_of_line ();
3110 indx = (int) get_absolute_expression ();
3112 /* FIXME: we don't have to save the name here. */
3113 name = demand_copy_C_string (&len);
3115 add_file (name, indx - 1);
3117 demand_empty_rest_of_line ();
3120 /* Parse .fmask directives. */
3123 obj_ecoff_fmask (ignore)
3128 if (cur_proc_ptr == (proc_t *) NULL)
3130 as_warn (".fmask outside of .ent");
3131 demand_empty_rest_of_line ();
3135 if (get_absolute_expression_and_terminator (&val) != ',')
3137 as_warn ("Bad .fmask directive");
3138 --input_line_pointer;
3139 demand_empty_rest_of_line ();
3143 cur_proc_ptr->pdr.fregmask = val;
3144 cur_proc_ptr->pdr.fregoffset = get_absolute_expression ();
3146 demand_empty_rest_of_line ();
3149 /* Parse .frame directives. */
3152 obj_ecoff_frame (ignore)
3157 if (cur_proc_ptr == (proc_t *) NULL)
3159 as_warn (".frame outside of .ent");
3160 demand_empty_rest_of_line ();
3164 cur_proc_ptr->pdr.framereg = tc_get_register ();
3167 if (*input_line_pointer++ != ','
3168 || get_absolute_expression_and_terminator (&val) != ',')
3170 as_warn ("Bad .frame directive");
3171 --input_line_pointer;
3172 demand_empty_rest_of_line ();
3176 cur_proc_ptr->pdr.frameoffset = val;
3178 cur_proc_ptr->pdr.pcreg = tc_get_register ();
3180 demand_empty_rest_of_line ();
3183 /* Parse .mask directives. */
3186 obj_ecoff_mask (ignore)
3191 if (cur_proc_ptr == (proc_t *) NULL)
3193 as_warn (".mask outside of .ent");
3194 demand_empty_rest_of_line ();
3198 if (get_absolute_expression_and_terminator (&val) != ',')
3200 as_warn ("Bad .mask directive");
3201 --input_line_pointer;
3202 demand_empty_rest_of_line ();
3206 cur_proc_ptr->pdr.regmask = val;
3207 cur_proc_ptr->pdr.regoffset = get_absolute_expression ();
3209 demand_empty_rest_of_line ();
3212 /* Parse .loc directives. */
3215 obj_ecoff_loc (ignore)
3218 lineno_list_t *list;
3220 if (cur_file_ptr == (efdr_t *) NULL)
3222 as_warn (".loc before .file");
3223 demand_empty_rest_of_line ();
3227 if (now_seg != text_section)
3229 as_warn (".loc outside of .text");
3230 demand_empty_rest_of_line ();
3234 /* Skip the file number. */
3236 get_absolute_expression ();
3239 /* If we're building stabs, then output a special label rather than
3240 ECOFF line number info. */
3243 (void) add_ecoff_symbol ((char *) NULL, st_Label, sc_Text,
3244 symbol_new ("L0\001", now_seg,
3245 frag_now_fix (), frag_now),
3246 0, get_absolute_expression ());
3250 list = allocate_lineno_list ();
3252 list->next = (lineno_list_t *) NULL;
3253 list->file = cur_file_ptr;
3254 list->proc = cur_proc_ptr;
3255 list->frag = frag_now;
3256 list->paddr = frag_now_fix ();
3257 list->lineno = get_absolute_expression ();
3259 /* A .loc directive will sometimes appear before a .ent directive,
3260 which means that cur_proc_ptr will be NULL here. Arrange to
3262 if (cur_proc_ptr == (proc_t *) NULL)
3266 pl = &noproc_lineno;
3267 while (*pl != (lineno_list_t *) NULL)
3273 *last_lineno_ptr = list;
3274 last_lineno_ptr = &list->next;
3278 /* Make sure the @stabs symbol is emitted. */
3286 /* Add a dummy @stabs dymbol. */
3288 (void) add_ecoff_symbol (stabs_symbol, stNil, scInfo,
3290 (symint_t) -1, MIPS_MARK_STAB (0));
3294 /* Parse .stabs directives.
3296 .stabs directives have five fields:
3297 "string" a string, encoding the type information.
3298 code a numeric code, defined in <stab.h>
3300 0 a zero or line number
3301 value a numeric value or an address.
3303 If the value is relocatable, we transform this into:
3304 iss points as an index into string space
3305 value value from lookup of the name
3306 st st from lookup of the name
3307 sc sc from lookup of the name
3308 index code|CODE_MASK
3310 If the value is not relocatable, we transform this into:
3311 iss points as an index into string space
3315 index code|CODE_MASK
3317 .stabn directives have four fields (string is null):
3318 code a numeric code, defined in <stab.h>
3320 0 a zero or a line number
3321 value a numeric value or an address. */
3324 obj_ecoff_stab (type)
3328 efdr_t *save_file_ptr = cur_file_ptr;
3335 if (stabs_seen == 0)
3339 string = (char *) NULL;
3344 string = demand_copy_C_string (&len);
3346 if (*input_line_pointer == ',')
3347 input_line_pointer++;
3350 as_warn ("Bad .stab%c directive", type);
3351 demand_empty_rest_of_line ();
3356 code = (symint_t) get_absolute_expression ();
3359 if (*input_line_pointer++ != ',')
3361 as_warn ("Bad .stab%c directive", type);
3362 --input_line_pointer;
3363 demand_empty_rest_of_line ();
3367 if (get_absolute_expression () != 0)
3369 as_warn ("Bad .stab%c directive (expected 0)", type);
3370 demand_empty_rest_of_line ();
3375 if (*input_line_pointer++ != ',')
3377 as_warn ("Bad .stab%c directive", type);
3378 --input_line_pointer;
3379 demand_empty_rest_of_line ();
3383 /* Line number stabs are handled differently, since they have two values,
3384 the line number and the address of the label. We use the index field
3385 (aka code) to hold the line number, and the value field to hold the
3386 address. The symbol type is st_Label, which should be different from
3387 the other stabs, so that gdb can recognize it. */
3388 if (code == N_SLINE)
3394 code = (symint_t) get_absolute_expression ();
3396 if (*input_line_pointer++ != ',')
3398 as_warn ("Bad .stab%c directive", type);
3399 --input_line_pointer;
3400 demand_empty_rest_of_line ();
3404 dummy_symr.index = code;
3405 if (dummy_symr.index != code)
3407 as_warn ("Line number (%d) for .stab%c directive cannot fit in index field (20 bits)",
3409 demand_empty_rest_of_line ();
3414 name = input_line_pointer;
3415 name_end = get_symbol_end ();
3417 sym = symbol_find_or_make (name);
3418 *input_line_pointer = name_end;
3426 /* The next number is sometimes the line number of the
3427 declaration. We have nowhere to put it, so we just ignore
3429 (void) get_absolute_expression ();
3432 if (*input_line_pointer++ != ',')
3434 as_warn ("Bad .stab%c directive", type);
3435 --input_line_pointer;
3436 demand_empty_rest_of_line ();
3441 if (isdigit (*input_line_pointer)
3442 || *input_line_pointer == '-'
3443 || *input_line_pointer == '+')
3447 sym = (symbolS *) NULL;
3448 value = get_absolute_expression ();
3450 else if (! is_name_beginner ((unsigned char) *input_line_pointer))
3452 as_warn ("Illegal .stab%c directive, bad character", type);
3453 demand_empty_rest_of_line ();
3461 name = input_line_pointer;
3462 name_end = get_symbol_end ();
3464 sym = symbol_find_or_make (name);
3470 *input_line_pointer = name_end;
3471 if (name_end == '+' || name_end == '-')
3473 ++input_line_pointer;
3474 value = get_absolute_expression ();
3475 if (name_end == '-')
3480 code = MIPS_MARK_STAB (code);
3483 (void) add_ecoff_symbol (string, st, sc, sym, value, code);
3485 /* Restore normal file type. */
3486 cur_file_ptr = save_file_ptr;
3489 /* Add bytes to the symbolic information buffer. */
3492 ecoff_add_bytes (buf, bufend, bufptr, need)
3502 need -= *bufend - bufptr;
3503 if (need < PAGE_SIZE)
3505 want = (*bufend - *buf) + need;
3506 *buf = xrealloc (*buf, want);
3507 *bufend = *buf + want;
3511 /* Adjust the symbolic information buffer to a longword boundary. */
3514 ecoff_longword_adjust (buf, bufend, offset, bufptrptr)
3520 if ((offset & 3) != 0)
3524 add = 4 - (offset & 3);
3525 if (*bufend - (*buf + offset) < add)
3526 (void) ecoff_add_bytes (buf, bufend, *buf + offset, add);
3527 memset (*buf + offset, 0, add);
3529 if (bufptrptr != (char **) NULL)
3530 *bufptrptr = *buf + offset;
3536 /* Build the line number information. */
3539 ecoff_build_lineno (buf, bufend, offset, linecntptr)
3546 register lineno_list_t *l;
3547 lineno_list_t *last;
3554 bufptr = *buf + offset;
3556 file = (efdr_t *) NULL;
3557 proc = (proc_t *) NULL;
3558 last = (lineno_list_t *) NULL;
3562 for (l = first_lineno; l != (lineno_list_t *) NULL; l = l->next)
3567 /* Get the offset to the memory address of the next line number
3568 (in words). Do this first, so that we can skip ahead to the
3569 next useful line number entry. */
3570 if (l->next == (lineno_list_t *) NULL)
3574 count = ((l->next->frag->fr_address + l->next->paddr
3575 - (l->frag->fr_address + l->paddr))
3579 /* Don't change last, so we still get the right delta. */
3584 if (l->file != file || l->proc != proc)
3586 if (l->proc != proc && proc != (proc_t *) NULL)
3587 proc->pdr.lnHigh = last->lineno;
3588 if (l->file != file && file != (efdr_t *) NULL)
3590 file->fdr.cbLine = c - file->fdr.cbLineOffset;
3591 /* The cline field is ill-documented. This is a guess
3592 at the right value. */
3593 file->fdr.cline = totcount + count;
3596 if (l->file != file)
3599 file->fdr.ilineBase = iline;
3600 file->fdr.cbLineOffset = c;
3602 if (l->proc != proc)
3605 if (proc != (proc_t *) NULL)
3607 proc->pdr.lnLow = l->lineno;
3608 proc->pdr.cbLineOffset = c - file->fdr.cbLineOffset;
3609 /* The iline field is ill-documented. This is a
3610 guess at the right value. */
3611 proc->pdr.iline = totcount;
3615 last = (lineno_list_t *) NULL;
3620 /* Get the offset to this line number. */
3621 if (last == (lineno_list_t *) NULL)
3624 delta = l->lineno - last->lineno;
3626 /* Put in the offset to this line number. */
3631 /* 1 is added to each count read. */
3633 /* We can only adjust the word count by up to 15 words at a
3645 if (delta >= -7 && delta <= 7)
3647 if (bufptr >= *bufend)
3648 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
3649 *bufptr++ = setcount + (delta << 4);
3657 if (*bufend - bufptr < 3)
3658 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 3);
3659 *bufptr++ = setcount + (8 << 4);
3660 if (delta < -0x8000)
3665 else if (delta > 0x7fff)
3675 *bufptr++ = set >> 8;
3676 *bufptr++ = set & 0xffff;
3681 /* Finish adjusting the count. */
3684 if (bufptr >= *bufend)
3685 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
3686 /* 1 is added to each count read. */
3705 if (proc != (proc_t *) NULL)
3706 proc->pdr.lnHigh = last->lineno;
3707 if (file != (efdr_t *) NULL)
3709 file->fdr.cbLine = c - file->fdr.cbLineOffset;
3710 file->fdr.cline = totcount;
3713 c = ecoff_longword_adjust (buf, bufend, c, &bufptr);
3715 if (linecntptr != (long *) NULL)
3716 *linecntptr = totcount;
3721 /* Build and swap out the symbols. */
3724 ecoff_build_symbols (buf,
3738 varray_t *ext_strings;
3739 struct hash_control *ext_str_hash;
3741 struct sym_ext *sym_out;
3742 struct ext_ext *ext_out;
3745 vlinks_t *file_link;
3747 sym_out = (struct sym_ext *) (*buf + offset);
3748 ext_out = (struct ext_ext *) (*extbuf + *extoffset);
3753 /* The symbols are stored by file. */
3754 for (file_link = file_desc.first;
3755 file_link != (vlinks_t *) NULL;
3756 file_link = file_link->next)
3763 if (file_link->next == (vlinks_t *) NULL)
3764 fil_cnt = file_desc.objects_last_page;
3766 fil_cnt = file_desc.objects_per_page;
3767 fil_ptr = file_link->datum->file;
3768 fil_end = fil_ptr + fil_cnt;
3769 for (; fil_ptr < fil_end; fil_ptr++)
3773 fil_ptr->fdr.isymBase = isym;
3775 for (sym_link = fil_ptr->symbols.first;
3776 sym_link != (vlinks_t *) NULL;
3777 sym_link = sym_link->next)
3780 localsym_t *sym_ptr;
3781 localsym_t *sym_end;
3783 if (sym_link->next == (vlinks_t *) NULL)
3784 sym_cnt = fil_ptr->symbols.objects_last_page;
3786 sym_cnt = fil_ptr->symbols.objects_per_page;
3787 sym_ptr = sym_link->datum->sym;
3788 sym_end = sym_ptr + sym_cnt;
3789 for (; sym_ptr < sym_end; sym_ptr++)
3795 know (sym_ptr->file_ptr == fil_ptr);
3797 /* If there is no associated gas symbol, then this
3798 is a pure debugging symbol. We have already
3799 added the name (if any) to fil_ptr->strings.
3800 Otherwise we must decide whether this is an
3801 external or a local symbol (actually, it may be
3802 both if the local provides additional debugging
3803 information for the external). */
3805 as_sym = sym_ptr->as_sym;
3806 if (as_sym != (symbolS *) NULL)
3810 /* The value of a block start symbol is the
3811 offset from the start of the procedure. For
3812 other symbols we just use the gas value. */
3813 if (sym_ptr->ecoff_sym.st == (int) st_Block
3814 && sym_ptr->ecoff_sym.sc == (int) sc_Text)
3816 know (sym_ptr->proc_ptr != (proc_t *) NULL);
3817 sym_ptr->ecoff_sym.value =
3818 (S_GET_VALUE (as_sym)
3819 - S_GET_VALUE (sym_ptr->proc_ptr->sym->as_sym));
3822 sym_ptr->ecoff_sym.value = S_GET_VALUE (as_sym);
3824 /* Get the type and storage class based on where
3825 the symbol actually wound up. Traditionally,
3826 N_LBRAC and N_RBRAC are *not* relocated. */
3827 indx = sym_ptr->ecoff_sym.index;
3828 if (sym_ptr->ecoff_sym.st == st_Nil
3829 && sym_ptr->ecoff_sym.sc == sc_Nil
3830 && (! MIPS_IS_STAB (&sym_ptr->ecoff_sym)
3831 || ((MIPS_UNMARK_STAB (indx) != N_LBRAC)
3832 && (MIPS_UNMARK_STAB (indx) != N_RBRAC))))
3835 const char *segname;
3839 seg = S_GET_SEGMENT (as_sym);
3840 segname = segment_name (seg);
3842 if (S_IS_EXTERNAL (as_sym)
3843 || ! S_IS_DEFINED (as_sym))
3845 else if (seg == text_section)
3850 if (! S_IS_DEFINED (as_sym)
3851 || as_sym->ecoff_undefined)
3853 if (S_GET_VALUE (as_sym) > 0
3854 && (S_GET_VALUE (as_sym)
3855 <= bfd_get_gp_size (stdoutput)))
3860 else if (S_IS_COMMON (as_sym))
3862 if (S_GET_VALUE (as_sym) > 0
3863 && (S_GET_VALUE (as_sym)
3864 <= bfd_get_gp_size (stdoutput)))
3869 else if (seg == text_section)
3871 else if (seg == data_section)
3873 else if (strcmp (segname, ".rdata") == 0)
3875 else if (strcmp (segname, ".sdata") == 0)
3877 else if (seg == bss_section)
3879 else if (strcmp (segname, ".sbss") == 0)
3884 sym_ptr->ecoff_sym.st = (int) st;
3885 sym_ptr->ecoff_sym.sc = (int) sc;
3888 /* This is just an external symbol if it is
3889 outside a procedure and it has a type.
3890 FIXME: g++ will generate symbols which have
3891 different names in the debugging information
3892 than the actual symbol. Should we handle
3894 if ((S_IS_EXTERNAL (as_sym)
3895 || ! S_IS_DEFINED (as_sym))
3896 && sym_ptr->proc_ptr == (proc_t *) NULL
3897 && sym_ptr->ecoff_sym.st != (int) st_Nil
3898 && ! MIPS_IS_STAB (&sym_ptr->ecoff_sym))
3901 /* If an st_end symbol has an associated gas
3902 symbol, then it is a local label created for
3903 a .bend or .end directive. Stabs line
3904 numbers will have \001 in the names. */
3906 && sym_ptr->ecoff_sym.st != st_End
3907 && strchr (sym_ptr->name, '\001') == 0)
3908 sym_ptr->ecoff_sym.iss =
3909 add_string (&fil_ptr->strings,
3915 /* We now know the index of this symbol; fill in
3916 locations that have been waiting for that
3918 if (sym_ptr->begin_ptr != (localsym_t *) NULL)
3920 localsym_t *begin_ptr;
3924 begin_ptr = sym_ptr->begin_ptr;
3925 know (begin_ptr->sym_index != -1);
3926 sym_ptr->ecoff_sym.index = begin_ptr->sym_index;
3927 if (sym_ptr->ecoff_sym.sc != (int) sc_Info)
3928 sym_ptr->ecoff_sym.iss = begin_ptr->ecoff_sym.iss;
3930 begin_type = begin_ptr->ecoff_sym.st;
3931 if (begin_type == st_File
3932 || begin_type == st_Block)
3934 begin_ptr->ecoff_sym.index = isym - ifilesym + 1;
3935 ecoff_swap_sym_out (stdoutput,
3936 &begin_ptr->ecoff_sym,
3937 (((struct sym_ext *)
3939 + begin_ptr->sym_index));
3943 know (begin_ptr->index_ptr != (aux_t *) NULL);
3944 begin_ptr->index_ptr->data.isym =
3945 isym - ifilesym + 1;
3948 /* The value of the symbol marking the end of a
3949 procedure is the size of the procedure. The
3950 value of the symbol marking the end of a
3951 block is the offset from the start of the
3952 procedure to the block. */
3953 if (begin_type == st_Proc)
3955 know (as_sym != (symbolS *) NULL);
3956 know (begin_ptr->as_sym != (symbolS *) NULL);
3957 sym_ptr->ecoff_sym.value =
3958 (S_GET_VALUE (as_sym)
3959 - S_GET_VALUE (begin_ptr->as_sym));
3961 else if (begin_type == st_Block
3962 && sym_ptr->ecoff_sym.sc != (int) sc_Info)
3964 know (as_sym != (symbolS *) NULL);
3965 know (sym_ptr->proc_ptr != (proc_t *) NULL);
3966 sym_ptr->ecoff_sym.value =
3967 (S_GET_VALUE (as_sym)
3968 - S_GET_VALUE (sym_ptr->proc_ptr->sym->as_sym));
3972 for (f = sym_ptr->forward_ref;
3973 f != (forward_t *) NULL;
3977 f->ifd_ptr->data.isym = fil_ptr->file_index;
3978 f->index_ptr->data.rndx.index = isym - ifilesym;
3983 if (*bufend - (char *) sym_out < sizeof (struct sym_ext))
3984 sym_out = ((struct sym_ext *)
3985 ecoff_add_bytes (buf, bufend,
3987 sizeof (struct sym_ext)));
3988 ecoff_swap_sym_out (stdoutput, &sym_ptr->ecoff_sym,
3992 sym_ptr->sym_index = isym;
3994 if (sym_ptr->proc_ptr != (proc_t *) NULL
3995 && sym_ptr->proc_ptr->sym == sym_ptr)
3996 sym_ptr->proc_ptr->pdr.isym = isym - ifilesym;
4001 /* If this is an external symbol, swap it out. */
4002 if (as_sym != (symbolS *) NULL
4003 && (S_IS_EXTERNAL (as_sym)
4004 || ! S_IS_DEFINED (as_sym))
4005 && ! MIPS_IS_STAB (&sym_ptr->ecoff_sym))
4009 memset (&ext, 0, sizeof ext);
4010 ext.asym = sym_ptr->ecoff_sym;
4011 ext.ifd = fil_ptr->file_index;
4012 ext.asym.iss = add_string (ext_strings,
4014 S_GET_NAME (as_sym),
4016 if (*extbufend - (char *) ext_out
4017 < sizeof (struct ext_ext))
4018 ext_out = ((struct ext_ext *)
4019 ecoff_add_bytes (extbuf, extbufend,
4021 sizeof (struct ext_ext)));
4022 ecoff_swap_ext_out (stdoutput, &ext, ext_out);
4023 ecoff_set_sym_index (as_sym->bsym, iext);
4029 fil_ptr->fdr.csym = isym - fil_ptr->fdr.isymBase;
4033 *extoffset += iext * sizeof (struct ext_ext);
4034 return offset + isym * sizeof (struct sym_ext);
4037 /* Swap out the procedure information. */
4040 ecoff_build_procs (buf, bufend, offset)
4045 struct pdr_ext *pdr_out;
4047 vlinks_t *file_link;
4049 pdr_out = (struct pdr_ext *) (*buf + offset);
4053 /* The procedures are stored by file. */
4054 for (file_link = file_desc.first;
4055 file_link != (vlinks_t *) NULL;
4056 file_link = file_link->next)
4062 if (file_link->next == (vlinks_t *) NULL)
4063 fil_cnt = file_desc.objects_last_page;
4065 fil_cnt = file_desc.objects_per_page;
4066 fil_ptr = file_link->datum->file;
4067 fil_end = fil_ptr + fil_cnt;
4068 for (; fil_ptr < fil_end; fil_ptr++)
4070 vlinks_t *proc_link;
4073 fil_ptr->fdr.ipdFirst = iproc;
4075 for (proc_link = fil_ptr->procs.first;
4076 proc_link != (vlinks_t *) NULL;
4077 proc_link = proc_link->next)
4083 if (proc_link->next == (vlinks_t *) NULL)
4084 proc_cnt = fil_ptr->procs.objects_last_page;
4086 proc_cnt = fil_ptr->procs.objects_per_page;
4087 proc_ptr = proc_link->datum->proc;
4088 proc_end = proc_ptr + proc_cnt;
4089 for (; proc_ptr < proc_end; proc_ptr++)
4093 adr = S_GET_VALUE (proc_ptr->sym->as_sym);
4096 fil_ptr->fdr.adr = adr;
4099 proc_ptr->pdr.adr = adr - fil_ptr->fdr.adr;
4100 if (*bufend - (char *) pdr_out < sizeof (struct pdr_ext))
4101 pdr_out = ((struct pdr_ext *)
4102 ecoff_add_bytes (buf, bufend,
4104 sizeof (struct pdr_ext)));
4105 ecoff_swap_pdr_out (stdoutput, &proc_ptr->pdr, pdr_out);
4110 fil_ptr->fdr.cpd = iproc - fil_ptr->fdr.ipdFirst;
4114 return offset + iproc * sizeof (struct pdr_ext);
4117 /* Swap out the aux information. */
4120 ecoff_build_aux (buf, bufend, offset)
4126 union aux_ext *aux_out;
4128 vlinks_t *file_link;
4130 bigendian = stdoutput->xvec->header_byteorder_big_p;
4132 aux_out = (union aux_ext *) (*buf + offset);
4136 /* The aux entries are stored by file. */
4137 for (file_link = file_desc.first;
4138 file_link != (vlinks_t *) NULL;
4139 file_link = file_link->next)
4145 if (file_link->next == (vlinks_t *) NULL)
4146 fil_cnt = file_desc.objects_last_page;
4148 fil_cnt = file_desc.objects_per_page;
4149 fil_ptr = file_link->datum->file;
4150 fil_end = fil_ptr + fil_cnt;
4151 for (; fil_ptr < fil_end; fil_ptr++)
4155 fil_ptr->fdr.fBigendian = bigendian;
4156 fil_ptr->fdr.iauxBase = iaux;
4157 for (aux_link = fil_ptr->aux_syms.first;
4158 aux_link != (vlinks_t *) NULL;
4159 aux_link = aux_link->next)
4165 if (aux_link->next == (vlinks_t *) NULL)
4166 aux_cnt = fil_ptr->aux_syms.objects_last_page;
4168 aux_cnt = fil_ptr->aux_syms.objects_per_page;
4169 aux_ptr = aux_link->datum->aux;
4170 aux_end = aux_ptr + aux_cnt;
4171 for (; aux_ptr < aux_end; aux_ptr++)
4173 if (*bufend - (char *) aux_out < sizeof (union aux_ext))
4174 aux_out = ((union aux_ext *)
4175 ecoff_add_bytes (buf, bufend,
4177 sizeof (union aux_ext)));
4178 switch (aux_ptr->type)
4181 ecoff_swap_tir_out (bigendian, &aux_ptr->data.ti,
4185 ecoff_swap_rndx_out (bigendian, &aux_ptr->data.rndx,
4189 AUX_PUT_DNLOW (bigendian, aux_ptr->data.dnLow,
4193 AUX_PUT_DNHIGH (bigendian, aux_ptr->data.dnHigh,
4197 AUX_PUT_ISYM (bigendian, aux_ptr->data.isym,
4201 AUX_PUT_ISS (bigendian, aux_ptr->data.iss,
4205 AUX_PUT_WIDTH (bigendian, aux_ptr->data.width,
4209 AUX_PUT_COUNT (bigendian, aux_ptr->data.count,
4218 fil_ptr->fdr.caux = iaux - fil_ptr->fdr.iauxBase;
4222 return offset + iaux * sizeof (union aux_ext);
4225 /* Copy out the strings from a varray_t. This returns the number of
4226 bytes copied, rather than the new offset. */
4229 ecoff_build_strings (buf, bufend, offset, vp)
4239 str_out = *buf + offset;
4243 for (str_link = vp->first;
4244 str_link != (vlinks_t *) NULL;
4245 str_link = str_link->next)
4249 if (str_link->next == (vlinks_t *) NULL)
4250 str_cnt = vp->objects_last_page;
4252 str_cnt = vp->objects_per_page;
4254 if (*bufend - str_out < str_cnt)
4255 str_out = ecoff_add_bytes (buf, bufend, str_out, str_cnt);
4257 memcpy (str_out, str_link->datum->byte, str_cnt);
4265 /* Dump out the local strings. */
4268 ecoff_build_ss (buf, bufend, offset)
4274 vlinks_t *file_link;
4278 for (file_link = file_desc.first;
4279 file_link != (vlinks_t *) NULL;
4280 file_link = file_link->next)
4286 if (file_link->next == (vlinks_t *) NULL)
4287 fil_cnt = file_desc.objects_last_page;
4289 fil_cnt = file_desc.objects_per_page;
4290 fil_ptr = file_link->datum->file;
4291 fil_end = fil_ptr + fil_cnt;
4292 for (; fil_ptr < fil_end; fil_ptr++)
4296 fil_ptr->fdr.issBase = iss;
4297 ss_cnt = ecoff_build_strings (buf, bufend, offset + iss,
4299 fil_ptr->fdr.cbSs = ss_cnt;
4304 return ecoff_longword_adjust (buf, bufend, offset + iss, (char **) NULL);
4307 /* Swap out the file descriptors. */
4310 ecoff_build_fdr (buf, bufend, offset)
4316 struct fdr_ext *fdr_out;
4317 vlinks_t *file_link;
4321 fdr_out = (struct fdr_ext *) (*buf + offset);
4323 for (file_link = file_desc.first;
4324 file_link != (vlinks_t *) NULL;
4325 file_link = file_link->next)
4331 if (file_link->next == (vlinks_t *) NULL)
4332 fil_cnt = file_desc.objects_last_page;
4334 fil_cnt = file_desc.objects_per_page;
4335 fil_ptr = file_link->datum->file;
4336 fil_end = fil_ptr + fil_cnt;
4337 for (; fil_ptr < fil_end; fil_ptr++)
4339 if (*bufend - (char *) fdr_out < sizeof (struct fdr_ext))
4340 fdr_out = ((struct fdr_ext *)
4341 ecoff_add_bytes (buf, bufend, (char *) fdr_out,
4342 sizeof (struct fdr_ext)));
4343 ecoff_swap_fdr_out (stdoutput, &fil_ptr->fdr, fdr_out);
4349 return offset + ifile * sizeof (struct fdr_ext);
4352 /* Set the vma for all the sections. */
4357 register bfd_vma addr;
4358 register asection *sec;
4361 for (sec = stdoutput->sections; sec != (asection *) NULL; sec = sec->next)
4363 bfd_set_section_vma (stdoutput, sec, addr);
4364 addr += bfd_section_size (stdoutput, sec);
4368 /* Adjust the value of a symbol by the vma of the section. */
4371 ecoff_frob_symbol (sym)
4374 static int setvma = 0;
4384 + bfd_get_section_vma (stdoutput,
4385 bfd_get_section (sym->bsym))));
4388 /* Swap out the symbols and debugging information for BFD. */
4396 efdr_t *hold_file_ptr;
4397 proc_t * hold_proc_ptr;
4406 varray_t ext_strings;
4407 static varray_t init_ext_strings = INIT_VARRAY (char);
4408 struct hash_control *ext_str_hash;
4411 /* Make sure we have a file. */
4412 if (first_file == (efdr_t *) NULL)
4413 add_file ((const char *) NULL, 0);
4415 /* Handle any top level tags. */
4416 for (ptag = top_tag_head->first_tag;
4417 ptag != (tag_t *) NULL;
4420 if (ptag->forward_ref != (forward_t *) NULL)
4421 add_unknown_tag (ptag);
4423 ptag_next = ptag->same_block;
4424 ptag->hash_ptr->tag_ptr = ptag->same_name;
4428 free_thead (top_tag_head);
4430 /* Output an ending symbol for all the files. We have to do this
4431 here for the last file, so we may as well do it for all of the
4433 for (fil_ptr = first_file;
4434 fil_ptr != (efdr_t *) NULL;
4435 fil_ptr = fil_ptr->next_file)
4437 cur_file_ptr = fil_ptr;
4438 (void) add_ecoff_symbol ((const char *) NULL,
4445 /* Look through the symbols. Add debugging information for each
4446 symbol that has not already received it. */
4447 hold_file_ptr = cur_file_ptr;
4448 hold_proc_ptr = cur_proc_ptr;
4449 cur_proc_ptr = (proc_t *) NULL;
4450 for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
4452 if (sym->ecoff_symbol
4453 || sym->ecoff_file == (efdr_t *) NULL)
4456 cur_file_ptr = sym->ecoff_file;
4457 add_ecoff_symbol ((const char *) NULL, st_Nil, sc_Nil, sym,
4458 S_GET_VALUE (sym), indexNil);
4460 cur_proc_ptr = hold_proc_ptr;
4461 cur_file_ptr = hold_file_ptr;
4463 /* Build the symbolic information. */
4464 hdr = &ecoff_data (stdoutput)->symbolic_header;
4466 buf = xmalloc (PAGE_SIZE);
4467 bufend = buf + PAGE_SIZE;
4469 /* Build the line number information. */
4470 hdr->cbLineOffset = offset;
4471 offset = ecoff_build_lineno (&buf, &bufend, offset, &hdr->ilineMax);
4472 hdr->cbLine = offset - hdr->cbLineOffset;
4474 /* We don't use dense numbers at all. */
4476 hdr->cbDnOffset = 0;
4478 /* We can't build the PDR table until we have built the symbols,
4479 because a PDR contains a symbol index. However, we set aside
4480 space at this point. */
4481 hdr->ipdMax = proc_cnt;
4482 hdr->cbPdOffset = offset;
4483 if (bufend - (buf + offset) < proc_cnt * sizeof (struct pdr_ext))
4484 (void) ecoff_add_bytes (&buf, &bufend, buf + offset,
4485 proc_cnt * sizeof (struct pdr_ext));
4486 offset += proc_cnt * sizeof (struct pdr_ext);
4488 /* Build the symbols. It's convenient to build both the local and
4489 external symbols at the same time. We can put the local symbols
4490 directly into the buffer, but we have to hold the external
4491 symbols apart until we know where they are going to go. */
4492 extbuf = xmalloc (PAGE_SIZE);
4493 extbufend = extbuf + PAGE_SIZE;
4495 ext_strings = init_ext_strings;
4496 ext_str_hash = hash_new ();
4497 hdr->cbSymOffset = offset;
4498 offset = ecoff_build_symbols (&buf, &bufend, offset,
4499 &extbuf, &extbufend, &extoffset,
4500 &ext_strings, ext_str_hash);
4501 hdr->isymMax = (offset - hdr->cbSymOffset) / sizeof (struct sym_ext);
4503 /* Building the symbols initializes the symbol index in the PDR's.
4504 Now we can swap out the PDR's. */
4505 (void) ecoff_build_procs (&buf, &bufend, hdr->cbPdOffset);
4507 /* We don't use optimization symbols. */
4509 hdr->cbOptOffset = 0;
4511 /* Swap out the auxiliary type information. */
4512 hdr->cbAuxOffset = offset;
4513 offset = ecoff_build_aux (&buf, &bufend, offset);
4514 hdr->iauxMax = (offset - hdr->cbAuxOffset) / sizeof (union aux_ext);
4516 /* Copy out the local strings. */
4517 hdr->cbSsOffset = offset;
4518 offset = ecoff_build_ss (&buf, &bufend, offset);
4519 hdr->issMax = offset - hdr->cbSsOffset;
4521 /* Copy out the external strings. */
4522 hdr->cbSsExtOffset = offset;
4523 offset += ecoff_build_strings (&buf, &bufend, offset, &ext_strings);
4524 offset = ecoff_longword_adjust (&buf, &bufend, offset, (char **) NULL);
4525 hdr->issExtMax = offset - hdr->cbSsExtOffset;
4527 /* We don't use relative file descriptors. */
4529 hdr->cbRfdOffset = 0;
4531 /* Swap out the file descriptors. */
4532 hdr->cbFdOffset = offset;
4533 offset = ecoff_build_fdr (&buf, &bufend, offset);
4534 hdr->ifdMax = (offset - hdr->cbFdOffset) / sizeof (struct fdr_ext);
4536 /* Copy out the external symbols. */
4537 hdr->cbExtOffset = offset;
4538 if (bufend - (buf + offset) < extoffset)
4539 (void) ecoff_add_bytes (&buf, &bufend, buf + offset, extoffset);
4540 memcpy (buf + offset, extbuf, extoffset);
4541 offset += extoffset;
4542 hdr->iextMax = (offset - hdr->cbExtOffset) / sizeof (struct ext_ext);
4544 know ((offset & 3) == 0);
4546 /* That completes the symbolic debugging information. We must now
4547 finish up the symbolic header and the ecoff_tdata structure. */
4549 #define SET(ptr, count, type) \
4550 ecoff_data (stdoutput)->ptr = (type *) set; \
4551 set += hdr->count * sizeof (type)
4553 SET (line, cbLine, unsigned char);
4554 SET (external_dnr, idnMax, struct dnr_ext);
4555 SET (external_pdr, ipdMax, struct pdr_ext);
4556 SET (external_sym, isymMax, struct sym_ext);
4557 SET (external_opt, ioptMax, struct opt_ext);
4558 SET (external_aux, iauxMax, union aux_ext);
4559 SET (ss, issMax, char);
4560 SET (ssext, issExtMax, char);
4561 SET (external_rfd, crfd, struct rfd_ext);
4562 SET (external_fdr, ifdMax, struct fdr_ext);
4563 SET (external_ext, iextMax, struct ext_ext);
4567 /* FIXME: set the register masks. */
4569 ecoff_data (stdoutput)->raw_size = offset;
4570 ecoff_data (stdoutput)->raw_syments = buf;
4572 hdr->magic = magicSym;
4573 /* FIXME: what should hdr->vstamp be? */
4576 /* Allocate a cluster of pages. */
4578 #ifndef MALLOC_CHECK
4581 allocate_cluster (npages)
4582 unsigned long npages;
4584 register page_t *value = (page_t *) xmalloc (npages * PAGE_USIZE);
4588 fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value);
4591 memset (value, 0, npages * PAGE_USIZE);
4597 static page_t *cluster_ptr = NULL;
4598 static unsigned long pages_left = 0;
4600 #endif /* MALLOC_CHECK */
4602 /* Allocate one page (which is initialized to 0). */
4607 #ifndef MALLOC_CHECK
4609 if (pages_left == 0)
4611 pages_left = MAX_CLUSTER_PAGES;
4612 cluster_ptr = allocate_cluster (pages_left);
4616 return cluster_ptr++;
4618 #else /* MALLOC_CHECK */
4622 ptr = xmalloc (PAGE_USIZE);
4623 memset (ptr, 0, PAGE_USIZE);
4626 #endif /* MALLOC_CHECK */
4629 /* Allocate scoping information. */
4634 register scope_t *ptr;
4635 static scope_t initial_scope;
4637 #ifndef MALLOC_CHECK
4639 ptr = alloc_counts[(int)alloc_type_scope].free_list.f_scope;
4640 if (ptr != (scope_t *) NULL)
4641 alloc_counts[ (int)alloc_type_scope ].free_list.f_scope = ptr->free;
4644 register int unallocated = alloc_counts[(int)alloc_type_scope].unallocated;
4645 register page_t *cur_page = alloc_counts[(int)alloc_type_scope].cur_page;
4647 if (unallocated == 0)
4649 unallocated = PAGE_SIZE / sizeof (scope_t);
4650 alloc_counts[(int)alloc_type_scope].cur_page = cur_page = allocate_page ();
4651 alloc_counts[(int)alloc_type_scope].total_pages++;
4654 ptr = &cur_page->scope[--unallocated];
4655 alloc_counts[(int)alloc_type_scope].unallocated = unallocated;
4660 ptr = (scope_t *) xmalloc (sizeof (scope_t));
4664 alloc_counts[(int)alloc_type_scope].total_alloc++;
4665 *ptr = initial_scope;
4669 /* Free scoping information. */
4675 alloc_counts[(int)alloc_type_scope].total_free++;
4677 #ifndef MALLOC_CHECK
4678 ptr->free = alloc_counts[(int)alloc_type_scope].free_list.f_scope;
4679 alloc_counts[(int)alloc_type_scope].free_list.f_scope = ptr;
4685 /* Allocate links for pages in a virtual array. */
4690 register vlinks_t *ptr;
4691 static vlinks_t initial_vlinks;
4693 #ifndef MALLOC_CHECK
4695 register int unallocated = alloc_counts[(int)alloc_type_vlinks].unallocated;
4696 register page_t *cur_page = alloc_counts[(int)alloc_type_vlinks].cur_page;
4698 if (unallocated == 0)
4700 unallocated = PAGE_SIZE / sizeof (vlinks_t);
4701 alloc_counts[(int)alloc_type_vlinks].cur_page = cur_page = allocate_page ();
4702 alloc_counts[(int)alloc_type_vlinks].total_pages++;
4705 ptr = &cur_page->vlinks[--unallocated];
4706 alloc_counts[(int)alloc_type_vlinks].unallocated = unallocated;
4710 ptr = (vlinks_t *) xmalloc (sizeof (vlinks_t));
4714 alloc_counts[(int)alloc_type_vlinks].total_alloc++;
4715 *ptr = initial_vlinks;
4719 /* Allocate string hash buckets. */
4724 register shash_t *ptr;
4725 static shash_t initial_shash;
4727 #ifndef MALLOC_CHECK
4729 register int unallocated = alloc_counts[(int)alloc_type_shash].unallocated;
4730 register page_t *cur_page = alloc_counts[(int)alloc_type_shash].cur_page;
4732 if (unallocated == 0)
4734 unallocated = PAGE_SIZE / sizeof (shash_t);
4735 alloc_counts[(int)alloc_type_shash].cur_page = cur_page = allocate_page ();
4736 alloc_counts[(int)alloc_type_shash].total_pages++;
4739 ptr = &cur_page->shash[--unallocated];
4740 alloc_counts[(int)alloc_type_shash].unallocated = unallocated;
4744 ptr = (shash_t *) xmalloc (sizeof (shash_t));
4748 alloc_counts[(int)alloc_type_shash].total_alloc++;
4749 *ptr = initial_shash;
4753 /* Allocate type hash buckets. */
4758 register thash_t *ptr;
4759 static thash_t initial_thash;
4761 #ifndef MALLOC_CHECK
4763 register int unallocated = alloc_counts[(int)alloc_type_thash].unallocated;
4764 register page_t *cur_page = alloc_counts[(int)alloc_type_thash].cur_page;
4766 if (unallocated == 0)
4768 unallocated = PAGE_SIZE / sizeof (thash_t);
4769 alloc_counts[(int)alloc_type_thash].cur_page = cur_page = allocate_page ();
4770 alloc_counts[(int)alloc_type_thash].total_pages++;
4773 ptr = &cur_page->thash[--unallocated];
4774 alloc_counts[(int)alloc_type_thash].unallocated = unallocated;
4778 ptr = (thash_t *) xmalloc (sizeof (thash_t));
4782 alloc_counts[(int)alloc_type_thash].total_alloc++;
4783 *ptr = initial_thash;
4787 /* Allocate structure, union, or enum tag information. */
4792 register tag_t *ptr;
4793 static tag_t initial_tag;
4795 #ifndef MALLOC_CHECK
4797 ptr = alloc_counts[(int)alloc_type_tag].free_list.f_tag;
4798 if (ptr != (tag_t *) NULL)
4799 alloc_counts[(int)alloc_type_tag].free_list.f_tag = ptr->free;
4802 register int unallocated = alloc_counts[(int)alloc_type_tag].unallocated;
4803 register page_t *cur_page = alloc_counts[(int)alloc_type_tag].cur_page;
4805 if (unallocated == 0)
4807 unallocated = PAGE_SIZE / sizeof (tag_t);
4808 alloc_counts[(int)alloc_type_tag].cur_page = cur_page = allocate_page ();
4809 alloc_counts[(int)alloc_type_tag].total_pages++;
4812 ptr = &cur_page->tag[--unallocated];
4813 alloc_counts[(int)alloc_type_tag].unallocated = unallocated;
4818 ptr = (tag_t *) xmalloc (sizeof (tag_t));
4822 alloc_counts[(int)alloc_type_tag].total_alloc++;
4827 /* Free scoping information. */
4833 alloc_counts[(int)alloc_type_tag].total_free++;
4835 #ifndef MALLOC_CHECK
4836 ptr->free = alloc_counts[(int)alloc_type_tag].free_list.f_tag;
4837 alloc_counts[(int)alloc_type_tag].free_list.f_tag = ptr;
4843 /* Allocate forward reference to a yet unknown tag. */
4848 register forward_t *ptr;
4849 static forward_t initial_forward;
4851 #ifndef MALLOC_CHECK
4853 register int unallocated = alloc_counts[(int)alloc_type_forward].unallocated;
4854 register page_t *cur_page = alloc_counts[(int)alloc_type_forward].cur_page;
4856 if (unallocated == 0)
4858 unallocated = PAGE_SIZE / sizeof (forward_t);
4859 alloc_counts[(int)alloc_type_forward].cur_page = cur_page = allocate_page ();
4860 alloc_counts[(int)alloc_type_forward].total_pages++;
4863 ptr = &cur_page->forward[--unallocated];
4864 alloc_counts[(int)alloc_type_forward].unallocated = unallocated;
4868 ptr = (forward_t *) xmalloc (sizeof (forward_t));
4872 alloc_counts[(int)alloc_type_forward].total_alloc++;
4873 *ptr = initial_forward;
4877 /* Allocate head of type hash list. */
4882 register thead_t *ptr;
4883 static thead_t initial_thead;
4885 #ifndef MALLOC_CHECK
4887 ptr = alloc_counts[(int)alloc_type_thead].free_list.f_thead;
4888 if (ptr != (thead_t *) NULL)
4889 alloc_counts[ (int)alloc_type_thead ].free_list.f_thead = ptr->free;
4892 register int unallocated = alloc_counts[(int)alloc_type_thead].unallocated;
4893 register page_t *cur_page = alloc_counts[(int)alloc_type_thead].cur_page;
4895 if (unallocated == 0)
4897 unallocated = PAGE_SIZE / sizeof (thead_t);
4898 alloc_counts[(int)alloc_type_thead].cur_page = cur_page = allocate_page ();
4899 alloc_counts[(int)alloc_type_thead].total_pages++;
4902 ptr = &cur_page->thead[--unallocated];
4903 alloc_counts[(int)alloc_type_thead].unallocated = unallocated;
4908 ptr = (thead_t *) xmalloc (sizeof (thead_t));
4912 alloc_counts[(int)alloc_type_thead].total_alloc++;
4913 *ptr = initial_thead;
4917 /* Free scoping information. */
4923 alloc_counts[(int)alloc_type_thead].total_free++;
4925 #ifndef MALLOC_CHECK
4926 ptr->free = (thead_t *) alloc_counts[(int)alloc_type_thead].free_list.f_thead;
4927 alloc_counts[(int)alloc_type_thead].free_list.f_thead = ptr;
4933 static lineno_list_t *
4934 allocate_lineno_list ()
4936 register lineno_list_t *ptr;
4937 static lineno_list_t initial_lineno_list;
4939 #ifndef MALLOC_CHECK
4941 register int unallocated = alloc_counts[(int)alloc_type_lineno].unallocated;
4942 register page_t *cur_page = alloc_counts[(int)alloc_type_lineno].cur_page;
4944 if (unallocated == 0)
4946 unallocated = PAGE_SIZE / sizeof (lineno_list_t);
4947 alloc_counts[(int)alloc_type_lineno].cur_page = cur_page = allocate_page ();
4948 alloc_counts[(int)alloc_type_lineno].total_pages++;
4951 ptr = &cur_page->lineno[--unallocated];
4952 alloc_counts[(int)alloc_type_lineno].unallocated = unallocated;
4956 ptr = (lineno_list_t *) xmalloc (sizeof (lineno_list_t));
4960 alloc_counts[(int)alloc_type_lineno].total_alloc++;
4961 *ptr = initial_lineno_list;